Skip to content

Commit 575dc11

Browse files
authored
Fix needlessly indexing unsearchable statuses into ElasticSearch (mastodon#12041)
1 parent 699f53c commit 575dc11

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

app/chewy/statuses_index.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ class StatusesIndex < Chewy::Index
3131
},
3232
}
3333

34-
define_type ::Status.unscoped.without_reblogs.includes(:media_attachments) do
34+
define_type ::Status.unscoped.kept.without_reblogs.includes(:media_attachments), delete_if: ->(status) { status.searchable_by.empty? } do
3535
crutch :mentions do |collection|
36-
data = ::Mention.where(status_id: collection.map(&:id)).pluck(:status_id, :account_id)
36+
data = ::Mention.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id)
3737
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
3838
end
3939

4040
crutch :favourites do |collection|
41-
data = ::Favourite.where(status_id: collection.map(&:id)).pluck(:status_id, :account_id)
41+
data = ::Favourite.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id)
4242
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
4343
end
4444

4545
crutch :reblogs do |collection|
46-
data = ::Status.where(reblog_of_id: collection.map(&:id)).pluck(:reblog_of_id, :account_id)
46+
data = ::Status.where(reblog_of_id: collection.map(&:id)).where(account: Account.local).pluck(:reblog_of_id, :account_id)
4747
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) }
4848
end
4949

app/models/status.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ class Status < ApplicationRecord
129129
REAL_TIME_WINDOW = 6.hours
130130

131131
def searchable_by(preloaded = nil)
132-
ids = [account_id]
132+
ids = []
133+
134+
ids << account_id if local?
133135

134136
if preloaded.nil?
135-
ids += mentions.pluck(:account_id)
136-
ids += favourites.pluck(:account_id)
137-
ids += reblogs.pluck(:account_id)
137+
ids += mentions.where(account: Account.local).pluck(:account_id)
138+
ids += favourites.where(account: Account.local).pluck(:account_id)
139+
ids += reblogs.where(account: Account.local).pluck(:account_id)
138140
else
139141
ids += preloaded.mentions[id] || []
140142
ids += preloaded.favourites[id] || []

0 commit comments

Comments
 (0)