Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request mastodon#1234 from pixiv/suggestion
Browse files Browse the repository at this point in the history
Limit statuses subquery in Account.triadic_closures
  • Loading branch information
abcang authored Feb 25, 2019
2 parents f846f2d + b12e1af commit 895fecb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 895fecb

Please sign in to comment.