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:
commit
f0d334ea69
3 changed files with 6 additions and 16 deletions
|
@ -105,22 +105,18 @@ module Types
|
||||||
def connection_usager
|
def connection_usager
|
||||||
if object.user_deleted?
|
if object.user_deleted?
|
||||||
:deleted
|
:deleted
|
||||||
else
|
elsif object.user_from_france_connect?
|
||||||
user_loader.then do |_user|
|
|
||||||
if object.user_from_france_connect?
|
|
||||||
:france_connect
|
:france_connect
|
||||||
else
|
else
|
||||||
:password
|
:password
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def usager
|
def usager
|
||||||
if object.user_deleted?
|
if object.user_deleted?
|
||||||
{ email: object.user_email_for(:display), id: '<deleted>' }
|
{ email: object.user_email_for(:display), id: '<deleted>' }
|
||||||
else
|
else
|
||||||
user_loader
|
object.user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -221,11 +217,5 @@ module Types
|
||||||
def self.authorized?(object, context)
|
def self.authorized?(object, context)
|
||||||
context.authorized_demarche?(object.revision.procedure)
|
context.authorized_demarche?(object.revision.procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def user_loader
|
|
||||||
Loaders::Record.for(User, includes: :france_connect_informations).load(object.user_id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -368,7 +368,7 @@ class Dossier < ApplicationRecord
|
||||||
.where.not(user: users_who_submitted)
|
.where.not(user: users_who_submitted)
|
||||||
end
|
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
|
scope :with_notifications, -> do
|
||||||
joins(:follows)
|
joins(:follows)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class DossierPreloader
|
||||||
|
|
||||||
def revisions(pj_template: false)
|
def revisions(pj_template: false)
|
||||||
@revisions ||= ProcedureRevision.where(id: @dossiers.pluck(:revision_id).uniq)
|
@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)
|
.index_by(&:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue