From f3f2b6acc266c48df56d332fff43c3d1752bf286 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 31 Jul 2017 18:35:34 +0200 Subject: [PATCH] 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