From 742e6f4a92f08391e46d9850187779f3f79ef39e Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 21 Mar 2024 16:37:41 +0100 Subject: [PATCH] perf(filter): we query by stable_id - no need to check type_de_champ private attribute --- app/models/dossier.rb | 7 +------ app/models/procedure_presentation.rb | 6 +++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 1c234d77b..fec977718 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -247,12 +247,7 @@ class Dossier < ApplicationRecord scope :with_type_de_champ, -> (stable_id) { joins('INNER JOIN champs ON champs.dossier_id = dossiers.id INNER JOIN types_de_champ ON types_de_champ.id = champs.type_de_champ_id') - .where('types_de_champ.private = FALSE AND types_de_champ.stable_id = ?', stable_id) - } - - scope :with_type_de_champ_private, -> (stable_id) { - joins('INNER JOIN champs ON champs.dossier_id = dossiers.id INNER JOIN types_de_champ ON types_de_champ.id = champs.type_de_champ_id') - .where('types_de_champ.private = TRUE AND types_de_champ.stable_id = ?', stable_id) + .where(types_de_champ: { stable_id: }) } scope :all_state, -> { not_archived.state_not_brouillon } diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 040e6319a..b5e981a45 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -163,7 +163,7 @@ class ProcedurePresentation < ApplicationRecord end when TYPE_DE_CHAMP_PRIVATE ids = dossiers - .with_type_de_champ_private(column) + .with_type_de_champ(column) .order("champs.value #{order}") .pluck(:id) if ids.size != count @@ -218,8 +218,8 @@ class ProcedurePresentation < ApplicationRecord dossiers.with_type_de_champ(column) .filter_ilike(:champs, value_column, values) when TYPE_DE_CHAMP_PRIVATE - dossiers.with_type_de_champ_private(column) - .filter_ilike(:champs_private, value_column, values) + dossiers.with_type_de_champ(column) + .filter_ilike(:champs, value_column, values) when 'etablissement' if column == 'entreprise_date_creation' dates = values