From 13bcd5d6af34a95c35e8eefdb73d21327fe409b6 Mon Sep 17 00:00:00 2001 From: retoor Date: Tue, 3 Dec 2024 03:21:25 +0000 Subject: [PATCH] fix: add missing GROUP BY clause to rants_of_user and posts_of_user views The rants_of_user and posts_of_user views were missing a GROUP BY clause on the username column, causing the GROUP_CONCAT aggregations to produce incorrect concatenated results across all rows instead of per-user groupings. This fix adds the required GROUP BY username to both view definitions, ensuring each user's rants and comments are properly aggregated into separate rows. --- src/drstats/db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drstats/db.py b/src/drstats/db.py index 6e96f39..47e2ffe 100644 --- a/src/drstats/db.py +++ b/src/drstats/db.py @@ -199,11 +199,11 @@ def get_db(): ) db.query("DROP VIEW IF EXISTS rants_of_user") db.query( - "CREATE VIEW rants_of_user as SELECT user_username as username, GROUP_CONCAT(text) as text FROM rants" + "CREATE VIEW rants_of_user as SELECT user_username as username, GROUP_CONCAT(text) as text FROM rants GROUP BY username" ) db.query("DROP VIEW IF EXISTS posts_of_user") db.query( - "CREATE VIEW posts_of_user AS SELECT user_username as username, GROUP_CONCAT(body) as text FROM comments" + "CREATE VIEW posts_of_user AS SELECT user_username as username, GROUP_CONCAT(body) as text FROM comments GROUP BY username" ) db.query("DROP VIEW IF EXISTS contributions_extended_ranked") db.query(