From 3159c0a54784f808f90a549a87b6440fee03a412 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 16 Apr 2024 05:17:03 -0400 Subject: [PATCH] Add scope `Status.list_eligible_visibility` (#29951) --- app/lib/feed_manager.rb | 6 +++--- app/models/status.rb | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 9ddc54c169..95a687fa41 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -109,7 +109,7 @@ class FeedManager def merge_into_home(from_account, into_account) timeline_key = key(:home, into_account.id) aggregate = into_account.user&.aggregates_reblogs? - query = from_account.statuses.where(visibility: [:public, :unlisted, :private]).includes(:preloadable_poll, :media_attachments, reblog: :account).limit(FeedManager::MAX_ITEMS / 4) + query = from_account.statuses.list_eligible_visibility.includes(:preloadable_poll, :media_attachments, reblog: :account).limit(FeedManager::MAX_ITEMS / 4) if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4 oldest_home_score = redis.zrange(timeline_key, 0, 0, with_scores: true).first.last.to_i @@ -135,7 +135,7 @@ class FeedManager def merge_into_list(from_account, list) timeline_key = key(:list, list.id) aggregate = list.account.user&.aggregates_reblogs? - query = from_account.statuses.where(visibility: [:public, :unlisted, :private]).includes(:preloadable_poll, :media_attachments, reblog: :account).limit(FeedManager::MAX_ITEMS / 4) + query = from_account.statuses.list_eligible_visibility.includes(:preloadable_poll, :media_attachments, reblog: :account).limit(FeedManager::MAX_ITEMS / 4) if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4 oldest_home_score = redis.zrange(timeline_key, 0, 0, with_scores: true).first.last.to_i @@ -274,7 +274,7 @@ class FeedManager next if last_status_score < oldest_home_score end - statuses = target_account.statuses.where(visibility: [:public, :unlisted, :private]).includes(:preloadable_poll, :media_attachments, :account, reblog: :account).limit(limit) + statuses = target_account.statuses.list_eligible_visibility.includes(:preloadable_poll, :media_attachments, :account, reblog: :account).limit(limit) crutches = build_crutches(account.id, statuses) statuses.each do |status| diff --git a/app/models/status.rb b/app/models/status.rb index 78186623c3..8ab78d09d6 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -121,6 +121,7 @@ class Status < ApplicationRecord scope :tagged_with_none, lambda { |tag_ids| where('NOT EXISTS (SELECT * FROM statuses_tags forbidden WHERE forbidden.status_id = statuses.id AND forbidden.tag_id IN (?))', tag_ids) } + scope :list_eligible_visibility, -> { where(visibility: %i(public unlisted private)) } after_create_commit :trigger_create_webhooks after_update_commit :trigger_update_webhooks