From 1cff51370f182e4e5d3edca540dfe20cb00356ba Mon Sep 17 00:00:00 2001 From: Bofh Date: Sat, 17 Dec 2022 20:05:27 +0100 Subject: [PATCH] Add last_n_active to limit db query by the latest N active users --- api/v1/database/mastodon/accounts/search/mod.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/api/v1/database/mastodon/accounts/search/mod.php b/api/v1/database/mastodon/accounts/search/mod.php index d882b26..900e64a 100644 --- a/api/v1/database/mastodon/accounts/search/mod.php +++ b/api/v1/database/mastodon/accounts/search/mod.php @@ -55,6 +55,7 @@ $sql_all = ' {newerThanNDays} a.suspended_at IS NULL ORDER BY a.updated_at DESC + {lastNActiveUsers} '; $instances = null; @@ -115,9 +116,20 @@ if (isset($_GET['no_statuses'])) 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; $cache = null; -if ($user_filter === 'local') +if ($user_filter === 'local' || ($last_n_active !== null && $last_n_active <= 5000)) $cache = 'ondemand,60'; else if ($user_filter === 'remote') { $cache = 'always,3600';