summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-10-16 10:43:19 +0200
committerYorhel <git@yorhel.nl>2020-10-16 10:43:31 +0200
commit2d629c33129e5b96562f7c87f9b78a8158b06e91 (patch)
treee4e3b3226c1ec99c5e297420e621672b43627293
parent739ab13ed3d0941237d9b29d1d62bd7d2ae31ac7 (diff)
reviews: Fix vote calculation when uid=NULL
The anonymous votes ended up not getting counted at all.
-rw-r--r--sql/func.sql4
1 files changed, 2 insertions, 2 deletions
diff --git a/sql/func.sql b/sql/func.sql
index 7728873a..3b0edfdb 100644
--- a/sql/func.sql
+++ b/sql/func.sql
@@ -192,8 +192,8 @@ CREATE OR REPLACE FUNCTION update_reviews_votes_cache(vndbid) RETURNS void AS $$
BEGIN
WITH stats(id,up,down) AS (
SELECT r.id
- , COALESCE(SUM(CASE WHEN rv.overrule THEN 100000 WHEN rv.ip IS NULL THEN 100 ELSE 1 END) FILTER(WHERE rv.vote AND NOT u.ign_votes AND r2.id IS NULL), 0)
- , COALESCE(SUM(CASE WHEN rv.overrule THEN 100000 WHEN rv.ip IS NULL THEN 100 ELSE 1 END) FILTER(WHERE NOT rv.vote AND NOT u.ign_votes AND r2.id IS NULL), 0)
+ , COALESCE(SUM(CASE WHEN rv.overrule THEN 100000 WHEN rv.ip IS NULL THEN 100 ELSE 1 END) FILTER(WHERE rv.vote AND u.ign_votes IS DISTINCT FROM true AND r2.id IS NULL), 0)
+ , COALESCE(SUM(CASE WHEN rv.overrule THEN 100000 WHEN rv.ip IS NULL THEN 100 ELSE 1 END) FILTER(WHERE NOT rv.vote AND u.ign_votes IS DISTINCT FROM true AND r2.id IS NULL), 0)
FROM reviews r
LEFT JOIN reviews_votes rv ON rv.id = r.id
LEFT JOIN users u ON u.id = rv.uid