From b12e1af5314fdfa4b4ca3197f380d8136994ef77 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Mon, 25 Feb 2019 16:31:44 +0900 Subject: [PATCH] Limit statuses subquery in Account.triadic_closures --- app/models/account.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 1b887bbb97e5e2..3761ff203f13cd 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -333,12 +333,12 @@ def triadic_closures(account, limit: 5, offset: 0, exclude_ids: [], current_time AND target_account_id NOT IN (:excluded_account_ids) AND accounts.suspended = false GROUP BY target_account_id, accounts.id - HAVING ( + HAVING EXISTS ( SELECT created_at FROM statuses - WHERE statuses.account_id = target_account_id + WHERE statuses.account_id = target_account_id AND statuses.id >= :oldest_id ORDER BY statuses.id DESC LIMIT 1 - ) >= TIMESTAMP :current_timestamp - '3 days'::INTERVAL + ) ORDER BY count(account_id) DESC OFFSET :offset LIMIT :limit @@ -347,7 +347,7 @@ def triadic_closures(account, limit: 5, offset: 0, exclude_ids: [], current_time excluded_account_ids = account.excluded_from_timeline_account_ids + [account.id] + exclude_ids find_by_sql( - [sql, { account_id: account.id, excluded_account_ids: excluded_account_ids, limit: limit, offset: offset, current_timestamp: current_time }] + [sql, { account_id: account.id, excluded_account_ids: excluded_account_ids, limit: limit, offset: offset, oldest_id: Mastodon::Snowflake.id_at(current_time - 3.days) }] ) end