From 9985cdccec9f7909e3801731404c3e158685420d Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 10 Oct 2023 14:57:05 +0200 Subject: [PATCH 1/2] refactor(expert): no n+1 user on avis index --- app/controllers/experts/avis_controller.rb | 5 +++-- app/views/experts/avis/procedure.html.haml | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/experts/avis_controller.rb b/app/controllers/experts/avis_controller.rb index 098a254ac..e3a22cfd9 100644 --- a/app/controllers/experts/avis_controller.rb +++ b/app/controllers/experts/avis_controller.rb @@ -15,7 +15,8 @@ module Experts def index avis = current_expert.avis .not_revoked - .includes(dossier: [groupe_instructeur: :procedure]) + .includes(:dossier) + .includes(procedure: { logo_attachment: :blob }) .not_hidden_by_administration @avis_by_procedure = avis.to_a.group_by(&:procedure) end @@ -30,7 +31,7 @@ module Experts expert_avis = current_expert .avis .not_revoked - .includes(:dossier) + .includes(dossier: :user) .not_hidden_by_administration .where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure) }) diff --git a/app/views/experts/avis/procedure.html.haml b/app/views/experts/avis/procedure.html.haml index 40edc6445..d36eba763 100644 --- a/app/views/experts/avis/procedure.html.haml +++ b/app/views/experts/avis/procedure.html.haml @@ -36,11 +36,11 @@ - @avis.each do |avis| %tr %td.number-col - = link_to(expert_avis_path(avis.procedure, avis), class: 'cell-link') do + = link_to(expert_avis_path(@procedure, avis), class: 'cell-link') do %span.icon.folder #{avis.dossier.id} - %td= link_to(avis.dossier.user_email_for(:display), expert_avis_path(avis.procedure, avis), class: 'cell-link') - %td= link_to(avis.procedure.libelle, expert_avis_path(avis.procedure, avis), class: 'cell-link') + %td= link_to(avis.dossier.user_email_for(:display), expert_avis_path(@procedure, avis), class: 'cell-link') + %td= link_to(@procedure.libelle, expert_avis_path(@procedure, avis), class: 'cell-link') = paginate @avis, views_prefix: 'shared' - else %h2.empty-text Aucun avis From 816a85800eb49b8cc59423e076aa0080a826cc1b Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 10 Oct 2023 14:58:37 +0200 Subject: [PATCH 2/2] refactor(expert): preload dossier --- app/controllers/experts/avis_controller.rb | 9 +++++++++ app/views/experts/avis/procedure.html.haml | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/experts/avis_controller.rb b/app/controllers/experts/avis_controller.rb index e3a22cfd9..2a38ed108 100644 --- a/app/controllers/experts/avis_controller.rb +++ b/app/controllers/experts/avis_controller.rb @@ -31,6 +31,7 @@ module Experts expert_avis = current_expert .avis .not_revoked + .includes(:procedure) .includes(dossier: :user) .not_hidden_by_administration .where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure) }) @@ -55,6 +56,7 @@ module Experts end def show + @dossier = dossier_with_champs end def instruction @@ -157,6 +159,8 @@ module Experts end def telecharger_pjs + @dossier = dossier_with_champs + files = ActiveStorage::DownloadableFile.create_list_from_dossiers(Dossier.where(id: @dossier.id), include_avis_for_expert: current_expert) cleaned_files = ActiveStorage::DownloadableFile.cleanup_list_from_dossier(files) @@ -200,6 +204,11 @@ module Experts @avis = current_expert.avis.find_by(id: params[:id]) redirect_to(expert_all_avis_path, flash: { alert: "Vous n’avez pas accès à cet avis." }) and return unless @avis @dossier = @avis.dossier + set_sentry_dossier(@dossier) + end + + def dossier_with_champs + DossierPreloader.load_one(@dossier, pj_template: false) end def avis_params diff --git a/app/views/experts/avis/procedure.html.haml b/app/views/experts/avis/procedure.html.haml index d36eba763..40edc6445 100644 --- a/app/views/experts/avis/procedure.html.haml +++ b/app/views/experts/avis/procedure.html.haml @@ -36,11 +36,11 @@ - @avis.each do |avis| %tr %td.number-col - = link_to(expert_avis_path(@procedure, avis), class: 'cell-link') do + = link_to(expert_avis_path(avis.procedure, avis), class: 'cell-link') do %span.icon.folder #{avis.dossier.id} - %td= link_to(avis.dossier.user_email_for(:display), expert_avis_path(@procedure, avis), class: 'cell-link') - %td= link_to(@procedure.libelle, expert_avis_path(@procedure, avis), class: 'cell-link') + %td= link_to(avis.dossier.user_email_for(:display), expert_avis_path(avis.procedure, avis), class: 'cell-link') + %td= link_to(avis.procedure.libelle, expert_avis_path(avis.procedure, avis), class: 'cell-link') = paginate @avis, views_prefix: 'shared' - else %h2.empty-text Aucun avis