perf(Instructeurs/Dossiers#demande): remove n+1

This commit is contained in:
mfo 2024-10-08 11:10:10 +02:00
parent c072ee7226
commit 5cba847d10
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 3 additions and 2 deletions

View file

@ -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

View file

@ -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