From a3375be7c5e2afdbf5562e2edafed11b1b3e69b7 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 11 Oct 2024 12:20:24 +0200 Subject: [PATCH] fix(graphql): n+1 on procedure and france_connect_informations --- app/graphql/types/dossier_type.rb | 18 ++++-------------- app/models/dossier.rb | 2 +- app/models/dossier_preloader.rb | 2 +- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/graphql/types/dossier_type.rb b/app/graphql/types/dossier_type.rb index 3236b3a4a..4a90b7cee 100644 --- a/app/graphql/types/dossier_type.rb +++ b/app/graphql/types/dossier_type.rb @@ -105,14 +105,10 @@ module Types def connection_usager if object.user_deleted? :deleted + elsif object.user_from_france_connect? + :france_connect else - user_loader.then do |_user| - if object.user_from_france_connect? - :france_connect - else - :password - end - end + :password end end @@ -120,7 +116,7 @@ module Types if object.user_deleted? { email: object.user_email_for(:display), id: '' } else - user_loader + object.user end end @@ -221,11 +217,5 @@ module Types def self.authorized?(object, context) context.authorized_demarche?(object.revision.procedure) end - - private - - def user_loader - Loaders::Record.for(User, includes: :france_connect_informations).load(object.user_id) - end end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9a980ae60..0d78d496d 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -368,7 +368,7 @@ class Dossier < ApplicationRecord .where.not(user: users_who_submitted) end - scope :for_api_v2, -> { includes(:attestation_template, revision: [procedure: [:administrateurs]], etablissement: [], individual: [], traitement: []) } + scope :for_api_v2, -> { includes(:attestation_template, revision: [procedure: [:administrateurs]], etablissement: [], individual: [], traitement: [], procedure: [], user: [:france_connect_informations]) } scope :with_notifications, -> do joins(:follows) diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index 23b18fd41..9b27f47cc 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -39,7 +39,7 @@ class DossierPreloader def revisions(pj_template: false) @revisions ||= ProcedureRevision.where(id: @dossiers.pluck(:revision_id).uniq) - .includes(revision_types_de_champ: { parent: :type_de_champ }, types_de_champ_public: [], types_de_champ_private: [], types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : []) + .includes(procedure: [], revision_types_de_champ: { parent: :type_de_champ }, types_de_champ_public: [], types_de_champ_private: [], types_de_champ: pj_template ? { piece_justificative_template_attachment: :blob } : []) .index_by(&:id) end