From 5cba847d1005cc1a93f89055b720a89f160ace1b Mon Sep 17 00:00:00 2001 From: mfo Date: Tue, 8 Oct 2024 11:10:10 +0200 Subject: [PATCH] perf(Instructeurs/Dossiers#demande): remove n+1 --- app/models/dossier_preloader.rb | 2 +- app/models/type_de_champ.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index 6882c23c9..23b18fd41 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -39,7 +39,7 @@ class DossierPreloader def revisions(pj_template: false) @revisions ||= ProcedureRevision.where(id: @dossiers.pluck(:revision_id).uniq) - .includes(types_de_champ_public: [], types_de_champ_private: [], types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : []) + .includes(revision_types_de_champ: { parent: :type_de_champ }, types_de_champ_public: [], types_de_champ_private: [], types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : []) .index_by(&:id) end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 015721c60..559f621b8 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -526,7 +526,8 @@ class TypeDeChamp < ApplicationRecord end def level_for_revision(revision) - rtdc = revision.revision_types_de_champ.includes(:type_de_champ, parent: :type_de_champ).find { |rtdc| rtdc.stable_id == stable_id } + rtdc = revision.revision_types_de_champ.find { |rtdc| rtdc.stable_id == stable_id } + if rtdc.child? header_section_level_value.to_i + rtdc.parent.type_de_champ.current_section_level(revision) elsif header_section_level_value