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)
.count
@all_dossiers_counts = {}
@all_dossiers_counts['à suivre'] = dossiers.without_followers.en_cours.count
@all_dossiers_counts['suivis'] = current_instructeur
.followed_dossiers
.joins(:groupe_instructeur)
.en_cours
.where(groupe_instructeur_id: groupe_ids)
.count
@all_dossiers_counts['traités'] = dossiers.termine.count
@all_dossiers_counts['dossiers'] = dossiers.all_state.count
@all_dossiers_counts['archivés'] = dossiers.archived.count
@all_dossiers_counts = {
'à suivre' => @dossiers_a_suivre_count_per_procedure.sum { |_, v| v },
'suivis' => @followed_dossiers_count_per_procedure.sum { |_, v| v },
'traités' => @dossiers_termines_count_per_procedure.sum { |_, v| v },
'dossiers' => @dossiers_count_per_procedure.sum { |_, v| v },
'archivés' => @dossiers_archived_count_per_procedure.sum { |_, v| v }
}
@procedure_ids_en_cours_with_notifications = current_instructeur.procedure_ids_with_notifications(:en_cours)
@procedure_ids_termines_with_notifications = current_instructeur.procedure_ids_with_notifications(:termine)
end
def show

View file

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

View file

@ -1,63 +1,61 @@
%ul.procedure-list
- procedures.each do |p|
%li.procedure-item.flex.align-start
= link_to(instructeur_procedure_path(p)) do
.flex
%li.procedure-item.flex.align-start
= link_to(instructeur_procedure_path(p)) do
.flex
.procedure-logo{ style: "background-image: url(#{p.logo_url})" }
.procedure-logo{ style: "background-image: url(#{p.logo_url})" }
.procedure-details
%p.procedure-title
= procedure_libelle p
%ul.procedure-stats.flex
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'a-suivre')) do
- a_suivre_count = dossiers_a_suivre_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(a_suivre_count)
.stats-legend
à suivre
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'suivis')) do
- if current_instructeur.procedures_with_notifications(:en_cours).include?(p)
%span.notifications{ 'aria-label': "notifications" }
- followed_count = followed_dossiers_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(followed_count)
.stats-legend
= t('pluralize.followed', count: followed_count)
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'traites')) do
- if current_instructeur.procedures_with_notifications(:termine).include?(p)
%span.notifications{ 'aria-label': "notifications" }
- termines_count = dossiers_termines_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(termines_count)
.stats-legend
= t('pluralize.processed', count: termines_count)
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'tous')) do
- dossier_count = dossiers_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(dossier_count)
.stats-legend
= t('pluralize.case', count: dossier_count)
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'archives')) do
- archived_count = dossiers_archived_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(archived_count)
.stats-legend
= t('pluralize.archived', count: archived_count)
.procedure-details
%p.procedure-title
= procedure_libelle p
%ul.procedure-stats.flex
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'a-suivre')) do
- a_suivre_count = dossiers_a_suivre_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(a_suivre_count)
.stats-legend
à suivre
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'suivis')) do
- if procedure_ids_en_cours_with_notifications.include?(p.id)
%span.notifications{ 'aria-label': "notifications" }
- followed_count = followed_dossiers_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(followed_count)
.stats-legend
= t('pluralize.followed', count: followed_count)
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'traites')) do
- if procedure_ids_termines_with_notifications.include?(p.id)
%span.notifications{ 'aria-label': "notifications" }
- termines_count = dossiers_termines_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(termines_count)
.stats-legend
= t('pluralize.processed', count: termines_count)
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'tous')) do
- dossier_count = dossiers_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(dossier_count)
.stats-legend
= t('pluralize.case', count: dossier_count)
%li
%object
= link_to(instructeur_procedure_path(p, statut: 'archives')) do
- archived_count = dossiers_archived_count_per_procedure[p.id] || 0
.stats-number
= number_with_html_delimiter(archived_count)
.stats-legend
= t('pluralize.archived', count: archived_count)
- if p.close?
.procedure-status
%span.label Close
- elsif p.depubliee?
.procedure-status
%span.label Dépubliée
- if p.close?
.procedure-status
%span.label Close
- elsif p.depubliee?
.procedure-status
%span.label Dépubliée

View file

@ -4,9 +4,14 @@
%h1.page-title Démarches
= render partial: 'instructeurs/procedures/synthese', locals: { procedures: @procedures, all_dossiers_counts: @all_dossiers_counts }
= render partial: 'instructeurs/procedures/list', locals: { procedures: @procedures,
dossiers_count_per_procedure: @dossiers_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_termines_count_per_procedure: @dossiers_termines_count_per_procedure,
followed_dossiers_count_per_procedure: @followed_dossiers_count_per_procedure }
%ul.procedure-list
= 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_archived_count_per_procedure: @dossiers_archived_count_per_procedure,
dossiers_termines_count_per_procedure: @dossiers_termines_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
describe '#notifications_per_procedure' do
describe '#procedure_ids_with_notifications' do
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
let(:instructeur) { dossier.follows.first.instructeur }
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
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