Merge pull request #10916 from tchak/graphql-fix-n+1

fix(graphql): n+1 on procedure and france_connect_informations
This commit is contained in:
Paul Chavard 2024-10-11 15:20:53 +00:00 committed by GitHub
commit f0d334ea69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 16 deletions

View file

@ -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: '<deleted>' }
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

View file

@ -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)

View file

@ -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