From d780ab1c904ca056554301f0c6c85461b0d666e2 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 31 Jul 2017 18:00:43 +0200 Subject: [PATCH 1/2] Avoid n+1 because of user.email --- app/controllers/new_gestionnaire/procedures_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index d806ee2d8..fab1883cb 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -27,19 +27,21 @@ module NewGestionnaire @a_suivre_dossiers = procedure .dossiers + .includes(:user) .without_followers .en_cours @followed_dossiers = current_gestionnaire .followed_dossiers + .includes(:user) .where(procedure: @procedure) .en_cours - @termines_dossiers = procedure.dossiers.termine + @termines_dossiers = procedure.dossiers.includes(:user).termine - @all_state_dossiers = procedure.dossiers.all_state + @all_state_dossiers = procedure.dossiers.includes(:user).all_state - @archived_dossiers = procedure.dossiers.archived + @archived_dossiers = procedure.dossiers.includes(:user).archived @statut = params[:statut].present? ? params[:statut] : 'a-suivre' From f3f2b6acc266c48df56d332fff43c3d1752bf286 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 31 Jul 2017 18:35:34 +0200 Subject: [PATCH 2/2] Avoid n+1 because of gestionnaire.follows?(dossier) --- app/controllers/new_gestionnaire/procedures_controller.rb | 5 +++++ .../new_gestionnaire/procedures/_dossier_actions.html.haml | 2 +- app/views/new_gestionnaire/procedures/show.html.haml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index fab1883cb..29f67e685 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -37,6 +37,11 @@ module NewGestionnaire .where(procedure: @procedure) .en_cours + @followed_dossiers_id = current_gestionnaire + .followed_dossiers + .where(procedure: @procedure) + .pluck(:id) + @termines_dossiers = procedure.dossiers.includes(:user).termine @all_state_dossiers = procedure.dossiers.includes(:user).all_state diff --git a/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml b/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml index 608671c6e..d61410fce 100644 --- a/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml +++ b/app/views/new_gestionnaire/procedures/_dossier_actions.html.haml @@ -1,5 +1,5 @@ - if dossier.en_construction_ou_instruction? - - if current_gestionnaire.follow?(dossier) + - if dossier_is_followed = link_to unfollow_dossier_path(procedure, dossier), method: :patch, class: 'button' do %i.unfollow> ne plus suivre diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index 0de5523d0..1c983751f 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -47,6 +47,6 @@ %td.status-col = link_to(dossier_path(@procedure, dossier), class: 'big-link') do = render partial: 'status', locals: { dossier: dossier } - %td.follow-col= render partial: 'dossier_actions', locals: { procedure: @procedure, dossier: dossier } + %td.follow-col= render partial: 'dossier_actions', locals: { procedure: @procedure, dossier: dossier, dossier_is_followed: @followed_dossiers_id.include?(dossier.id) } - else %h2 Aucun dossier