Fix error MethodError in Chewy::Strategy::Sidekiq::Worker (#17912)

Also refactor a bit to reduce code duplication.
remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
Claire 2022-03-31 00:49:24 +02:00 committed by GitHub
parent 8c7223f4ea
commit ef196c913c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 11 deletions

View File

@ -59,7 +59,7 @@ class StatusesIndex < Chewy::Index
field :id, type: 'long' field :id, type: 'long'
field :account_id, type: 'long' field :account_id, type: 'long'
field :text, type: 'text', value: ->(status) { [status.spoiler_text, extract_status_plain_text(status)].concat(status.ordered_media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do field :text, type: 'text', value: ->(status) { status.searchable_text } do
field :stemmed, type: 'text', analyzer: 'content' field :stemmed, type: 'text', analyzer: 'content'
end end

View File

@ -12,6 +12,7 @@ module FormattingHelper
def extract_status_plain_text(status) def extract_status_plain_text(status)
PlainTextFormatter.new(status.text, status.local?).to_s PlainTextFormatter.new(status.text, status.local?).to_s
end end
module_function :extract_status_plain_text
def status_content_format(status) def status_content_format(status)
html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : [])) html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))

View File

@ -5,7 +5,6 @@ require 'singleton'
class FeedManager class FeedManager
include Singleton include Singleton
include Redisable include Redisable
include FormattingHelper
# Maximum number of items stored in a single feed # Maximum number of items stored in a single feed
MAX_ITEMS = 400 MAX_ITEMS = 400
@ -443,16 +442,8 @@ class FeedManager
return false if active_filters.empty? return false if active_filters.empty?
combined_regex = Regexp.union(active_filters) combined_regex = Regexp.union(active_filters)
status = status.reblog if status.reblog?
combined_text = [ combined_regex.match?(status.proper.searchable_text)
extract_status_plain_text(status),
status.spoiler_text,
status.preloadable_poll ? status.preloadable_poll.options.join("\n\n") : nil,
status.ordered_media_attachments.map(&:description).join("\n\n"),
].compact.join("\n\n")
combined_regex.match?(combined_text)
end end
# Adds a status to an account's feed, returning true if a status was # Adds a status to an account's feed, returning true if a status was

View File

@ -155,6 +155,15 @@ class Status < ApplicationRecord
ids.uniq ids.uniq
end end
def searchable_text
[
spoiler_text,
FormattingHelper.extract_status_plain_text(self),
preloadable_poll ? preloadable_poll.options.join("\n\n") : nil,
ordered_media_attachments.map(&:description).join("\n\n"),
].compact.join("\n\n")
end
def reply? def reply?
!in_reply_to_id.nil? || attributes['reply'] !in_reply_to_id.nil? || attributes['reply']
end end