diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index 6dd4fb18b024dc..67284b2c8faf62 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -63,13 +63,14 @@ class StatusesIndex < Chewy::Index end root date_detection: false do - field :id, type: 'long' - field :account_id, type: 'long' + field(:id, type: 'long') + field(:account_id, type: 'long') - field :text, type: 'text', value: ->(status) { status.searchable_text } do - field :stemmed, type: 'text', analyzer: 'content' + field(:text, type: 'text', value: ->(status) { status.searchable_text }) do + field(:stemmed, type: 'text', analyzer: 'content') end - field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) } + field(:searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }) + field(:publicly_searchable, type: 'boolean', value: ->(status) { status.publicly_searchable? }) end end diff --git a/app/models/account.rb b/app/models/account.rb index aa2cb395db4c4f..629a63ed3ac1e6 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -79,6 +79,7 @@ class Account < ApplicationRecord include DomainMaterializable include AccountMerging include AccountSearch + include AccountStatusesSearch enum protocol: { ostatus: 0, activitypub: 1 } enum suspension_origin: { local: 0, remote: 1 }, _prefix: true @@ -124,6 +125,7 @@ class Account < ApplicationRecord scope :not_domain_blocked_by_account, ->(account) { where(arel_table[:domain].eq(nil).or(arel_table[:domain].not_in(account.excluded_from_timeline_domains))) } after_update_commit :trigger_update_webhooks + after_update :update_statuses_index!, if: :saved_change_to_discoverable? and Chewy.enabled? delegate :email, :unconfirmed_email, diff --git a/app/models/concerns/account_statuses_search.rb b/app/models/concerns/account_statuses_search.rb new file mode 100644 index 00000000000000..99b4a7a3898450 --- /dev/null +++ b/app/models/concerns/account_statuses_search.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module AccountStatusesSearch + extend ActiveSupport::Concern + + def update_statuses_index! + Chewy.strategy(:sidekiq) do + StatusesIndex.import(query: Status.where(account_id: id)) + end + end +end diff --git a/app/models/concerns/status_search.rb b/app/models/concerns/status_search.rb new file mode 100644 index 00000000000000..be106d0bcc32e3 --- /dev/null +++ b/app/models/concerns/status_search.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module StatusSearch + extend ActiveSupport::Concern + + def publicly_searchable? + public_visibility? && account.discoverable? + end +end diff --git a/app/models/status.rb b/app/models/status.rb index 67463b140b4c81..0cd2b35362f585 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -37,6 +37,7 @@ class Status < ApplicationRecord include StatusSnapshotConcern include RateLimitable include StatusSafeReblogInsert + include StatusSearch rate_limit by: :account, family: :statuses