perf(admin): remove N+1 on procedures index about instructeurs or groupe instructeurs count

This commit is contained in:
Colin Darie 2024-10-14 12:20:24 +02:00
parent 8e1b636901
commit df0e0e9c3e
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 43 additions and 39 deletions

View file

@ -24,43 +24,6 @@ module Administrateurs
@statut.blank? ? @statut = 'publiees' : @statut = params[:statut]
end
def paginated_published_procedures
current_administrateur
.procedures
.publiees
.page(params[:page])
.per(ITEMS_PER_PAGE)
.order(published_at: :desc)
end
def paginated_draft_procedures
current_administrateur
.procedures
.brouillons
.page(params[:page])
.per(ITEMS_PER_PAGE)
.order(created_at: :desc)
end
def paginated_closed_procedures
current_administrateur
.procedures
.closes
.page(params[:page])
.per(ITEMS_PER_PAGE)
.order(created_at: :desc)
end
def paginated_deleted_procedures
current_administrateur
.procedures
.with_discarded
.discarded
.page(params[:page])
.per(ITEMS_PER_PAGE)
.order(created_at: :desc)
end
def apercu
@dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user)
DossierPreloader.load_one(@dossier)
@ -464,6 +427,47 @@ module Administrateurs
private
def paginated_published_procedures
paginate_procedures(current_administrateur
.procedures
.publiees
.order(published_at: :desc))
end
def paginated_draft_procedures
paginate_procedures(current_administrateur
.procedures
.brouillons
.order(created_at: :desc))
end
def paginated_closed_procedures
paginate_procedures(current_administrateur
.procedures
.closes
.order(created_at: :desc))
end
def paginated_deleted_procedures
paginate_procedures(current_administrateur
.procedures
.with_discarded
.discarded
.order(created_at: :desc))
end
def paginate_procedures(procedures)
procedures
.with_attached_logo
.left_joins(groupe_instructeurs: :instructeurs)
.select('procedures.*,
COUNT(DISTINCT groupe_instructeurs.id) AS groupe_instructeurs_count,
COUNT(DISTINCT instructeurs.id) AS instructeurs_count')
.group('procedures.id')
.page(params[:page])
.per(ITEMS_PER_PAGE)
end
def filter_procedures(filter)
if filter.service_siret.present?
service = Service.find_by(siret: filter.service_siret)

View file

@ -45,9 +45,9 @@
%div
= dsfr_icon('fr-icon-team-fill')
- if procedure.routing_enabled?
%span.fr-badge= procedure.groupe_instructeurs.count
%span.fr-badge= procedure.groupe_instructeurs_count
- else
%span.fr-badge= procedure.instructeurs.count
%span.fr-badge= procedure.instructeurs_count
= dsfr_icon('fr-icon-file-text-fill fr-ml-1w')
%span.fr-badge= procedure.dossiers.state_not_brouillon.visible_by_administration.count