Merge pull request #5559 from betagouv/various_instructeur_dashboard_perf_improvements

Améliorations des performances du tableau de bord instructeur
This commit is contained in:
LeSim 2020-09-11 11:51:48 +02:00 committed by GitHub
commit af3fc98907
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 87 deletions

View file

@ -30,17 +30,16 @@ module Instructeurs
.reorder(nil) .reorder(nil)
.count .count
@all_dossiers_counts = {} @all_dossiers_counts = {
@all_dossiers_counts['à suivre'] = dossiers.without_followers.en_cours.count 'à suivre' => @dossiers_a_suivre_count_per_procedure.sum { |_, v| v },
@all_dossiers_counts['suivis'] = current_instructeur 'suivis' => @followed_dossiers_count_per_procedure.sum { |_, v| v },
.followed_dossiers 'traités' => @dossiers_termines_count_per_procedure.sum { |_, v| v },
.joins(:groupe_instructeur) 'dossiers' => @dossiers_count_per_procedure.sum { |_, v| v },
.en_cours 'archivés' => @dossiers_archived_count_per_procedure.sum { |_, v| v }
.where(groupe_instructeur_id: groupe_ids) }
.count
@all_dossiers_counts['traités'] = dossiers.termine.count @procedure_ids_en_cours_with_notifications = current_instructeur.procedure_ids_with_notifications(:en_cours)
@all_dossiers_counts['dossiers'] = dossiers.all_state.count @procedure_ids_termines_with_notifications = current_instructeur.procedure_ids_with_notifications(:termine)
@all_dossiers_counts['archivés'] = dossiers.archived.count
end end
def show def show

View file

@ -144,17 +144,14 @@ class Instructeur < ApplicationRecord
.with_notifications(self) .with_notifications(self)
end end
def procedures_with_notifications(scope) def procedure_ids_with_notifications(scope)
dossiers = Dossier groupe_instructeur_ids = Dossier
.send(scope) # :en_cours or :termine (or any other Dossier scope) .send(scope) # :en_cours or :termine (or any other Dossier scope)
.merge(followed_dossiers) .merge(followed_dossiers)
.with_notifications(self) .with_notifications(self)
.select(:groupe_instructeur_id)
Procedure GroupeInstructeur.where(id: groupe_instructeur_ids).pluck(:procedure_id)
.where(id: dossiers.joins(:groupe_instructeur)
.select('groupe_instructeurs.procedure_id')
.distinct)
.distinct
end end
def mark_tab_as_seen(dossier, tab) def mark_tab_as_seen(dossier, tab)

View file

@ -1,6 +1,4 @@
%ul.procedure-list %li.procedure-item.flex.align-start
- procedures.each do |p|
%li.procedure-item.flex.align-start
= link_to(instructeur_procedure_path(p)) do = link_to(instructeur_procedure_path(p)) do
.flex .flex
@ -21,7 +19,7 @@
%li %li
%object %object
= link_to(instructeur_procedure_path(p, statut: 'suivis')) do = link_to(instructeur_procedure_path(p, statut: 'suivis')) do
- if current_instructeur.procedures_with_notifications(:en_cours).include?(p) - if procedure_ids_en_cours_with_notifications.include?(p.id)
%span.notifications{ 'aria-label': "notifications" } %span.notifications{ 'aria-label': "notifications" }
- followed_count = followed_dossiers_count_per_procedure[p.id] || 0 - followed_count = followed_dossiers_count_per_procedure[p.id] || 0
.stats-number .stats-number
@ -31,7 +29,7 @@
%li %li
%object %object
= link_to(instructeur_procedure_path(p, statut: 'traites')) do = link_to(instructeur_procedure_path(p, statut: 'traites')) do
- if current_instructeur.procedures_with_notifications(:termine).include?(p) - if procedure_ids_termines_with_notifications.include?(p.id)
%span.notifications{ 'aria-label': "notifications" } %span.notifications{ 'aria-label': "notifications" }
- termines_count = dossiers_termines_count_per_procedure[p.id] || 0 - termines_count = dossiers_termines_count_per_procedure[p.id] || 0
.stats-number .stats-number

View file

@ -4,9 +4,14 @@
%h1.page-title Démarches %h1.page-title Démarches
= render partial: 'instructeurs/procedures/synthese', locals: { procedures: @procedures, all_dossiers_counts: @all_dossiers_counts } = render partial: 'instructeurs/procedures/synthese', locals: { procedures: @procedures, all_dossiers_counts: @all_dossiers_counts }
= render partial: 'instructeurs/procedures/list', locals: { procedures: @procedures, %ul.procedure-list
dossiers_count_per_procedure: @dossiers_count_per_procedure, = render partial: 'instructeurs/procedures/list',
collection: @procedures,
as: :p,
locals: { dossiers_count_per_procedure: @dossiers_count_per_procedure,
dossiers_a_suivre_count_per_procedure: @dossiers_a_suivre_count_per_procedure, dossiers_a_suivre_count_per_procedure: @dossiers_a_suivre_count_per_procedure,
dossiers_archived_count_per_procedure: @dossiers_archived_count_per_procedure, dossiers_archived_count_per_procedure: @dossiers_archived_count_per_procedure,
dossiers_termines_count_per_procedure: @dossiers_termines_count_per_procedure, dossiers_termines_count_per_procedure: @dossiers_termines_count_per_procedure,
followed_dossiers_count_per_procedure: @followed_dossiers_count_per_procedure } followed_dossiers_count_per_procedure: @followed_dossiers_count_per_procedure,
procedure_ids_en_cours_with_notifications: @procedure_ids_en_cours_with_notifications,
procedure_ids_termines_with_notifications: @procedure_ids_termines_with_notifications }

View file

@ -352,17 +352,17 @@ describe Instructeur, type: :model do
end end
end end
describe '#notifications_per_procedure' do describe '#procedure_ids_with_notifications' do
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) } let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
let(:instructeur) { dossier.follows.first.instructeur } let(:instructeur) { dossier.follows.first.instructeur }
let(:procedure) { dossier.procedure } let(:procedure) { dossier.procedure }
subject { instructeur.procedures_with_notifications(:en_cours) } subject { instructeur.procedure_ids_with_notifications(:en_cours) }
context 'when there is a modification on public champs' do context 'when there is a modification on public champs' do
before { dossier.update!(last_champ_updated_at: Time.zone.now) } before { dossier.update!(last_champ_updated_at: Time.zone.now) }
it { is_expected.to match([procedure]) } it { is_expected.to match([procedure.id]) }
end end
end end