refactor(search): rename update search terms => index search terms
This commit is contained in:
parent
797bd6b94b
commit
39b0327237
16 changed files with 36 additions and 35 deletions
7
app/jobs/dossier_index_search_terms_job.rb
Normal file
7
app/jobs/dossier_index_search_terms_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class DossierIndexSearchTermsJob < ApplicationJob
|
||||
discard_on ActiveRecord::RecordNotFound
|
||||
|
||||
def perform(dossier)
|
||||
dossier.index_search_terms
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
class DossierUpdateSearchTermsJob < ApplicationJob
|
||||
discard_on ActiveRecord::RecordNotFound
|
||||
|
||||
def perform(dossier)
|
||||
dossier.update_search_terms
|
||||
end
|
||||
end
|
|
@ -4,13 +4,13 @@ module DossierSearchableConcern
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_commit :update_search_terms_later
|
||||
after_commit :index_search_terms_later
|
||||
|
||||
SEARCH_TERMS_DEBOUNCE = 30.seconds
|
||||
|
||||
kredis_flag :debounce_update_search_terms_flag
|
||||
kredis_flag :debounce_index_search_terms_flag
|
||||
|
||||
def update_search_terms
|
||||
def index_search_terms
|
||||
DossierPreloader.load_one(self)
|
||||
|
||||
search_terms = [
|
||||
|
@ -28,11 +28,11 @@ module DossierSearchableConcern
|
|||
self.class.connection.execute(sanitized_sql)
|
||||
end
|
||||
|
||||
def update_search_terms_later
|
||||
return if debounce_update_search_terms_flag.marked?
|
||||
def index_search_terms_later
|
||||
return if debounce_index_search_terms_flag.marked?
|
||||
|
||||
debounce_update_search_terms_flag.mark(expires_in: SEARCH_TERMS_DEBOUNCE)
|
||||
DossierUpdateSearchTermsJob.set(wait: SEARCH_TERMS_DEBOUNCE).perform_later(self)
|
||||
debounce_index_search_terms_flag.mark(expires_in: SEARCH_TERMS_DEBOUNCE)
|
||||
DossierIndexSearchTermsJob.set(wait: SEARCH_TERMS_DEBOUNCE).perform_later(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ class Etablissement < ApplicationRecord
|
|||
fermé: "fermé"
|
||||
}, _prefix: true
|
||||
|
||||
after_commit -> { dossier&.debounce_update_search_terms }
|
||||
after_commit -> { dossier&.index_search_terms_later }
|
||||
|
||||
def entreprise_raison_sociale
|
||||
read_attribute(:entreprise_raison_sociale).presence || raison_sociale_for_ei
|
||||
|
|
|
@ -17,7 +17,7 @@ class Individual < ApplicationRecord
|
|||
|
||||
validates :email, presence: true, if: -> { dossier.for_tiers? && self.email? }, on: :update
|
||||
|
||||
after_commit -> { dossier.debounce_update_search_terms }, if: -> { nom_previously_changed? || prenom_previously_changed? }
|
||||
after_commit -> { dossier.index_search_terms_later }, if: -> { nom_previously_changed? || prenom_previously_changed? }
|
||||
|
||||
GENDER_MALE = "M."
|
||||
GENDER_FEMALE = 'Mme'
|
||||
|
|
|
@ -44,7 +44,7 @@ if Rails.env.production? && SIDEKIQ_ENABLED
|
|||
self.queue_adapter = :sidekiq
|
||||
end
|
||||
|
||||
class DossierUpdateSearchTermsJob < ApplicationJob
|
||||
class DossierIndexSearchTermsJob < ApplicationJob
|
||||
self.queue_adapter = :sidekiq
|
||||
end
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ describe RechercheController, type: :controller do
|
|||
dossier_with_expert.champs_private[1].value = "Dossier B is invalid"
|
||||
dossier_with_expert.save!
|
||||
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
RSpec.describe DossierUpdateSearchTermsJob, type: :job do
|
||||
RSpec.describe DossierIndexSearchTermsJob, type: :job do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
subject(:perform_job) { described_class.perform_now(dossier.reload) }
|
|
@ -51,7 +51,7 @@ RSpec.describe DossierCloneConcern do
|
|||
it "updates search terms" do
|
||||
subject
|
||||
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
sql = "SELECT search_terms, private_search_terms FROM dossiers where id = :id"
|
||||
result = Dossier.connection.execute(Dossier.sanitize_sql_array([sql, id: new_dossier.id])).first
|
||||
|
||||
|
@ -338,7 +338,7 @@ RSpec.describe DossierCloneConcern do
|
|||
|
||||
it { expect { subject }.to change { dossier.reload.champs.size }.by(0) }
|
||||
it { expect { subject }.not_to change { dossier.reload.champs.order(:created_at).reject { _1.stable_id.in?([99, 994]) }.map(&:value) } }
|
||||
it { expect { subject }.to have_enqueued_job(DossierUpdateSearchTermsJob).with(dossier) }
|
||||
it { expect { subject }.to have_enqueued_job(DossierIndexSearchTermsJob).with(dossier) }
|
||||
it { expect { subject }.to change { dossier.reload.champs.find { _1.stable_id == 99 }.value }.from('old value').to('new value') }
|
||||
it { expect { subject }.to change { dossier.reload.champs.find { _1.stable_id == 994 }.value }.from('old value').to('new value in repetition') }
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ describe DossierSearchableConcern do
|
|||
let(:champ_public) { dossier.champs_public.first }
|
||||
let(:champ_private) { dossier.champs_private.first }
|
||||
|
||||
describe '#update_search_terms' do
|
||||
describe '#index_search_terms' do
|
||||
let(:etablissement) { dossier.etablissement }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, user: user) }
|
||||
let(:etablissement) { build(:etablissement, entreprise_nom: 'Dupont', entreprise_prenom: 'Thomas', association_rna: '12345', association_titre: 'asso de test', association_objet: 'tests unitaires') }
|
||||
|
@ -20,7 +20,7 @@ describe DossierSearchableConcern do
|
|||
it "update columns" do
|
||||
champ_public.update_attribute(:value, "champ public")
|
||||
champ_private.update_attribute(:value, "champ privé")
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
|
||||
expect(result["search_terms"]).to eq("#{user.email} champ public #{etablissement.entreprise_siren} #{etablissement.entreprise_numero_tva_intracommunautaire} #{etablissement.entreprise_forme_juridique} #{etablissement.entreprise_forme_juridique_code} #{etablissement.entreprise_nom_commercial} #{etablissement.entreprise_raison_sociale} #{etablissement.entreprise_siret_siege_social} #{etablissement.entreprise_nom} #{etablissement.entreprise_prenom} #{etablissement.association_rna} #{etablissement.association_titre} #{etablissement.association_objet} #{etablissement.siret} #{etablissement.naf} #{etablissement.libelle_naf} #{etablissement.adresse} #{etablissement.code_postal} #{etablissement.localite} #{etablissement.code_insee_localite}")
|
||||
expect(result["private_search_terms"]).to eq('champ privé')
|
||||
|
@ -37,21 +37,21 @@ describe DossierSearchableConcern do
|
|||
champs_private_attributes: [{ id: champ_private.id, value: 'nouvelle valeur privee' }]
|
||||
)
|
||||
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
|
||||
expect(result["search_terms"]).to include('nouvelle valeur publique')
|
||||
expect(result["private_search_terms"]).to include('nouvelle valeur privee')
|
||||
end
|
||||
|
||||
it "debounce jobs" do
|
||||
assert_enqueued_jobs(1, only: DossierUpdateSearchTermsJob) do
|
||||
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do
|
||||
3.times { dossier.index_search_terms_later }
|
||||
end
|
||||
|
||||
# wait redis key expiration
|
||||
sleep 1.01.seconds
|
||||
|
||||
assert_enqueued_jobs(1, only: DossierUpdateSearchTermsJob) do
|
||||
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do
|
||||
dossier.update(champs_public_attributes: [{ id: champ_public.id, value: rand(10).to_s }])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -119,7 +119,7 @@ describe Etablissement do
|
|||
let(:etablissement) { create(:etablissement, dossier: build(:dossier)) }
|
||||
|
||||
it "schedule update search terms" do
|
||||
assert_enqueued_jobs(1, only: DossierUpdateSearchTermsJob) do
|
||||
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do
|
||||
etablissement.update(entreprise_nom: "nom")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,9 +36,10 @@ describe Individual do
|
|||
end
|
||||
end
|
||||
|
||||
it "schedule update search terms" do
|
||||
assert_enqueued_jobs(1, only: DossierUpdateSearchTermsJob) do
|
||||
subject
|
||||
it "schedule index search terms" do
|
||||
subject.dossier.debounce_index_search_terms_flag.remove
|
||||
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do
|
||||
individual.update(nom: "new name")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ describe DossierSearchService do
|
|||
dossier_3
|
||||
dossier_archived
|
||||
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
end
|
||||
|
||||
let(:procedure_1) { create(:procedure, :published, administrateur: administrateur_1) }
|
||||
|
@ -116,7 +116,7 @@ describe DossierSearchService do
|
|||
dossier_2
|
||||
dossier_3
|
||||
dossier_archived
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
end
|
||||
|
||||
let(:liste_dossiers) do
|
||||
|
|
|
@ -134,7 +134,7 @@ describe 'The routing with rules', js: true do
|
|||
user_send_dossier(litteraire_user, 'littéraire')
|
||||
user_send_dossier(artistique_user, 'artistique')
|
||||
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
|
||||
# the litteraires instructeurs only manage the litteraires dossiers
|
||||
register_instructeur_and_log_in(victor.email)
|
||||
|
|
|
@ -162,7 +162,7 @@ describe 'Invitations' do
|
|||
before do
|
||||
navigate_to_invited_dossier(invite)
|
||||
visit dossiers_path
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
end
|
||||
|
||||
it "can search by id and it displays the dossier" do
|
||||
|
|
|
@ -268,7 +268,7 @@ describe 'user access to the list of their dossiers', js: true do
|
|||
context 'when it matches multiple dossiers' do
|
||||
let!(:dossier_with_champs) { create(:dossier, :with_populated_champs, :en_construction, user: user) }
|
||||
before do
|
||||
perform_enqueued_jobs(only: DossierUpdateSearchTermsJob)
|
||||
perform_enqueued_jobs(only: DossierIndexSearchTermsJob)
|
||||
find('.fr-search-bar .fr-btn').click
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue