From 0bc17a3d48eeed102af3b4d733f0ff8ad2f9f62b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 14 Mar 2024 05:31:57 -0400 Subject: [PATCH] Use enum-generated `public_visibility` scope on Status (#28156) --- app/models/concerns/account/statuses_search.rb | 2 +- app/models/concerns/status/search_concern.rb | 2 +- app/models/public_feed.rb | 2 +- app/models/status.rb | 1 - spec/search/models/concerns/account/statuses_search_spec.rb | 4 ++-- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/account/statuses_search.rb b/app/models/concerns/account/statuses_search.rb index 334b714504..93452b78b0 100644 --- a/app/models/concerns/account/statuses_search.rb +++ b/app/models/concerns/account/statuses_search.rb @@ -31,7 +31,7 @@ module Account::StatusesSearch def add_to_public_statuses_index! return unless Chewy.enabled? - statuses.without_reblogs.where(visibility: :public).reorder(nil).find_in_batches do |batch| + statuses.without_reblogs.public_visibility.reorder(nil).find_in_batches do |batch| PublicStatusesIndex.import(batch) end end diff --git a/app/models/concerns/status/search_concern.rb b/app/models/concerns/status/search_concern.rb index c16db8bd8c..3f31b3b675 100644 --- a/app/models/concerns/status/search_concern.rb +++ b/app/models/concerns/status/search_concern.rb @@ -4,7 +4,7 @@ module Status::SearchConcern extend ActiveSupport::Concern included do - scope :indexable, -> { without_reblogs.where(visibility: :public).joins(:account).where(account: { indexable: true }) } + scope :indexable, -> { without_reblogs.public_visibility.joins(:account).where(account: { indexable: true }) } end def searchable_by diff --git a/app/models/public_feed.rb b/app/models/public_feed.rb index c208d6f664..1e2cca4d38 100644 --- a/app/models/public_feed.rb +++ b/app/models/public_feed.rb @@ -61,7 +61,7 @@ class PublicFeed end def public_scope - Status.with_public_visibility.joins(:account).merge(Account.without_suspended.without_silenced) + Status.public_visibility.joins(:account).merge(Account.without_suspended.without_silenced) end def local_only_scope diff --git a/app/models/status.rb b/app/models/status.rb index 0ec69c8dd1..a9c0ea70f1 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -108,7 +108,6 @@ class Status < ApplicationRecord scope :with_accounts, ->(ids) { where(id: ids).includes(:account) } scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') } scope :without_reblogs, -> { where(statuses: { reblog_of_id: nil }) } - scope :with_public_visibility, -> { where(visibility: :public) } scope :tagged_with, ->(tag_ids) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag_ids }) } scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) } scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) } diff --git a/spec/search/models/concerns/account/statuses_search_spec.rb b/spec/search/models/concerns/account/statuses_search_spec.rb index 915bc094cb..a1b0bf405c 100644 --- a/spec/search/models/concerns/account/statuses_search_spec.rb +++ b/spec/search/models/concerns/account/statuses_search_spec.rb @@ -21,7 +21,7 @@ describe Account::StatusesSearch, :sidekiq_inline do account.indexable = true account.save! - expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.where(visibility: :public).count) + expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.public_visibility.count) expect(StatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.count) end end @@ -32,7 +32,7 @@ describe Account::StatusesSearch, :sidekiq_inline do context 'when picking an indexable account' do it 'has statuses in the PublicStatusesIndex' do - expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.where(visibility: :public).count) + expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.public_visibility.count) end it 'has statuses in the StatusesIndex' do