demarches-normaliennes/app/models/concerns/dossier_searchable_concern.rb
Colin Darie f6ebfe0e47
fix(dossier): sync search_terms after merge
Use a job instead of a lot of reloads
2023-05-09 18:49:52 +02:00

23 lines
579 B
Ruby

module DossierSearchableConcern
extend ActiveSupport::Concern
included do
before_save :update_search_terms
def update_search_terms
self.search_terms = [
user&.email,
*champs_public.flat_map(&:search_terms),
*etablissement&.search_terms,
individual&.nom,
individual&.prenom
].compact_blank.join(' ')
self.private_search_terms = champs_private.flat_map(&:search_terms).compact_blank.join(' ')
end
def update_search_terms_later
DossierUpdateSearchTermsJob.perform_later(self)
end
end
end