Add last_n_active to limit db query by the latest N active users

This commit is contained in:
Bofh 2022-12-17 20:05:27 +01:00
parent 2c118b54bf
commit 1cff51370f
1 changed files with 13 additions and 1 deletions

View File

@ -55,6 +55,7 @@ $sql_all = '
{newerThanNDays} {newerThanNDays}
a.suspended_at IS NULL a.suspended_at IS NULL
ORDER BY a.updated_at DESC ORDER BY a.updated_at DESC
{lastNActiveUsers}
'; ';
$instances = null; $instances = null;
@ -115,9 +116,20 @@ if (isset($_GET['no_statuses']))
else $sql_all = str_replace('{noStatusesWhere}', '', $sql_all); else $sql_all = str_replace('{noStatusesWhere}', '', $sql_all);
$last_n_active = null;
if (isset($_GET['last_n_active'])) {
$last_n_active = intval($_GET['last_n_active']);
if ($last_n_active < 0)
$last_n_active = 1;
}
if ($last_n_active !== null)
$sql_all = str_replace('{lastNActiveUsers}', 'LIMIT '.intval($_GET['last_n_active']), $sql_all);
else $sql_all = str_replace('{lastNActiveUsers}', '', $sql_all);
$only_cached = false; $only_cached = false;
$cache = null; $cache = null;
if ($user_filter === 'local') if ($user_filter === 'local' || ($last_n_active !== null && $last_n_active <= 5000))
$cache = 'ondemand,60'; $cache = 'ondemand,60';
else if ($user_filter === 'remote') { else if ($user_filter === 'remote') {
$cache = 'always,3600'; $cache = 'always,3600';