[Nodeinfo] Count active users for full days and without silenced

This commit is contained in:
Alexei Sorokin 2020-04-17 18:13:05 +03:00 committed by Diogo Peralta Cordeiro
parent 9396539f58
commit 7b1c3dbb3f
1 changed files with 13 additions and 11 deletions

View File

@ -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 = <<<END
SELECT COUNT(DISTINCT profile_id) AS active_users_count
FROM (
SELECT profile_id FROM notice
WHERE notice.created >= 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);