From 4e9e370eb14c63700a94c897f88a25ffeb49c73e Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Sat, 30 May 2026 21:29:16 +0700 Subject: [PATCH] feat: enhance getTopViolators query to use conditional counts for improved accuracy in moderation stats --- src/moderation/analyticsStore.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/moderation/analyticsStore.ts b/src/moderation/analyticsStore.ts index e171c9e..7a1dc38 100644 --- a/src/moderation/analyticsStore.ts +++ b/src/moderation/analyticsStore.ts @@ -515,8 +515,12 @@ export async function getTopViolators(input: { AND deleted_at IS NULL ${channelId ? `AND (channel_id = ? OR thread_id = ?)` : ""} GROUP BY user_id, username, avatar_url - HAVING flagged_count > 0 OR warned_count > 0 - ORDER BY (flagged_count * 3 + warned_count) DESC + HAVING count(case when ai_status = 'flagged' then 1 end) > 0 + OR count(case when ai_status = 'warn' then 1 end) > 0 + ORDER BY ( + count(case when ai_status = 'flagged' then 1 end) * 3 + + count(case when ai_status = 'warn' then 1 end) + ) DESC LIMIT ? `, channelId