From 872bb1388d6eb447662a30e8995c029f39670b6c Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Fri, 17 Apr 2020 18:13:05 +0300 Subject: [PATCH] [Nodeinfo] Count active users for full days and without silenced --- plugins/Nodeinfo/actions/nodeinfo_2_0.php | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/Nodeinfo/actions/nodeinfo_2_0.php b/plugins/Nodeinfo/actions/nodeinfo_2_0.php index 5be14aecb0..9cc114a03d 100644 --- a/plugins/Nodeinfo/actions/nodeinfo_2_0.php +++ b/plugins/Nodeinfo/actions/nodeinfo_2_0.php @@ -327,17 +327,19 @@ class Nodeinfo_2_0Action extends Action public function getActiveUsers(int $days): int { $userTable = common_database_tablename('user'); - $query = " - SELECT COUNT(DISTINCT profile_id) AS active_users_count - FROM ( - SELECT profile_id FROM notice - WHERE notice.created >= (CURRENT_TIMESTAMP - INTERVAL '{$days}' DAY) AND notice.is_local = 1 - UNION ALL - SELECT user_id FROM fave INNER JOIN {$userTable} ON fave.user_id = {$userTable}.id - WHERE fave.created >= (CURRENT_TIMESTAMP - INTERVAL '{$days}' DAY) - UNION ALL - SELECT id FROM {$userTable} WHERE {$userTable}.created >= (CURRENT_TIMESTAMP - INTERVAL '{$days}' DAY) - ) AS source"; + $query = <<= CURRENT_DATE - INTERVAL '{$days}' DAY AND notice.is_local = 1 + UNION ALL + SELECT user_id FROM fave INNER JOIN {$userTable} ON fave.user_id = {$userTable}.id + WHERE fave.created >= CURRENT_DATE - INTERVAL '{$days}' DAY + UNION ALL + SELECT id FROM {$userTable} WHERE {$userTable}.created >= CURRENT_DATE - INTERVAL '{$days}' DAY + ) AS source + WHERE profile_id NOT IN (SELECT profile_id FROM profile_role WHERE role = 'silenced') + END; $activeUsersCount = new DB_DataObject(); $activeUsersCount->query($query);