From ea383278160bcee81477e86a95107d4a2dc315ef Mon Sep 17 00:00:00 2001 From: Jeong Arm Date: Sun, 24 Apr 2022 04:47:27 +0900 Subject: [PATCH] Let votes statuses are also searchable (#18070) --- app/chewy/statuses_index.rb | 5 +++++ app/models/status.rb | 2 ++ 2 files changed, 7 insertions(+) diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index 1381a96ed4..1304aeedbd 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -55,6 +55,11 @@ class StatusesIndex < Chewy::Index data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } end + crutch :votes do |collection| + data = ::PollVote.joins(:poll).where(poll: { status_id: collection.map(&:id) }).where(account: Account.local).pluck(:status_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end + root date_detection: false do field :id, type: 'long' field :account_id, type: 'long' diff --git a/app/models/status.rb b/app/models/status.rb index a71451f50a..288d374fd3 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -145,11 +145,13 @@ class Status < ApplicationRecord ids += favourites.where(account: Account.local).pluck(:account_id) ids += reblogs.where(account: Account.local).pluck(:account_id) ids += bookmarks.where(account: Account.local).pluck(:account_id) + ids += poll.votes.where(account: Account.local).pluck(:account_id) if poll.present? else ids += preloaded.mentions[id] || [] ids += preloaded.favourites[id] || [] ids += preloaded.reblogs[id] || [] ids += preloaded.bookmarks[id] || [] + ids += preloaded.votes[id] || [] end ids.uniq