perf(graphql): benchmark demarches_publiques query
This commit is contained in:
parent
5db8ba32b5
commit
03fbe506f6
6 changed files with 57 additions and 49 deletions
|
@ -72,7 +72,7 @@ class API::V2::Schema < GraphQL::Schema
|
|||
|
||||
use GraphQL::Execution::Interpreter
|
||||
use GraphQL::Analysis::AST
|
||||
use GraphQL::Schema::Timeout, max_seconds: 30
|
||||
use GraphQL::Schema::Timeout, max_seconds: 10
|
||||
use GraphQL::Batch
|
||||
use GraphQL::Backtrace
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ module Types
|
|||
|
||||
def champ_descriptors
|
||||
if object.type_de_champ.repetition?
|
||||
Loaders::Association.for(object.class, :revision_types_de_champ).load(object)
|
||||
Loaders::Association.for(object.class, revision_types_de_champ: :type_de_champ).load(object)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ module Types
|
|||
argument :number, Int, "Numéro du groupe instructeur.", required: true
|
||||
end
|
||||
|
||||
field :demarches_publiques, DemarcheDescriptorType.connection_type, null: false, internal: true, max_page_size: 30
|
||||
field :demarches_publiques, DemarcheDescriptorType.connection_type, null: false, internal: true
|
||||
|
||||
def demarches_publiques
|
||||
Procedure.opendata
|
||||
Procedure.opendata.includes(draft_revision: :procedure, published_revision: :procedure)
|
||||
end
|
||||
|
||||
def demarche(number:)
|
||||
|
|
|
@ -30,60 +30,21 @@ class DemarchesPubliquesExportService
|
|||
end
|
||||
|
||||
def execute_query(cursor: nil)
|
||||
result = API::V2::Schema.execute(query, variables: { cursor: cursor }, context: { internal_use: true })
|
||||
raise DemarchesPubliquesExportService::Error.new(result["errors"]) if result["errors"]
|
||||
@graphql_data = result["data"]
|
||||
end
|
||||
|
||||
def query
|
||||
"query($cursor: String) {
|
||||
demarchesPubliques(after: $cursor) {
|
||||
pageInfo {
|
||||
endCursor
|
||||
hasNextPage
|
||||
}
|
||||
edges {
|
||||
node {
|
||||
number
|
||||
title
|
||||
description
|
||||
datePublication
|
||||
service { nom organisme typeOrganisme }
|
||||
cadreJuridique
|
||||
deliberation
|
||||
dossiersCount
|
||||
revision {
|
||||
champDescriptors {
|
||||
type
|
||||
label
|
||||
description
|
||||
required
|
||||
options
|
||||
champDescriptors {
|
||||
type
|
||||
label
|
||||
description
|
||||
required
|
||||
options
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}"
|
||||
@graphql_data = SerializerService.demarches_publiques(after: cursor)
|
||||
rescue => e
|
||||
raise DemarchesPubliquesExportService::Error.new(e.message)
|
||||
end
|
||||
|
||||
def last_cursor
|
||||
@graphql_data["demarchesPubliques"]["pageInfo"]["endCursor"]
|
||||
@graphql_data["pageInfo"]["endCursor"]
|
||||
end
|
||||
|
||||
def has_next_page?
|
||||
@graphql_data["demarchesPubliques"]["pageInfo"]["hasNextPage"]
|
||||
@graphql_data["pageInfo"]["hasNextPage"]
|
||||
end
|
||||
|
||||
def demarches
|
||||
@graphql_data["demarchesPubliques"]["edges"].map { |edge| edge["node"] }
|
||||
@graphql_data["nodes"]
|
||||
end
|
||||
|
||||
def jsonify(demarches)
|
||||
|
|
|
@ -9,6 +9,11 @@ class SerializerService
|
|||
data && data['demarche']['dossiers']
|
||||
end
|
||||
|
||||
def self.demarches_publiques(after: nil)
|
||||
data = execute_query('serializeDemarchesPubliques', { after: after })
|
||||
data && data['demarchesPubliques']
|
||||
end
|
||||
|
||||
def self.avis(avis)
|
||||
data = execute_query('serializeAvis', { number: avis.dossier_id, id: avis.to_typed_id })
|
||||
data && data['dossier']['avis'].first
|
||||
|
@ -50,6 +55,18 @@ class SerializerService
|
|||
}
|
||||
}
|
||||
|
||||
query serializeDemarchesPubliques($after: String) {
|
||||
demarchesPubliques(after: $after) {
|
||||
nodes {
|
||||
...DemarcheDescriptorFragment
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query serializeDossier($number: Int!) {
|
||||
dossier(number: $number) {
|
||||
...DossierFragment
|
||||
|
@ -260,5 +277,34 @@ class SerializerService
|
|||
byteSize: byteSizeBigInt
|
||||
contentType
|
||||
}
|
||||
|
||||
fragment ChampDescriptorFragment on ChampDescriptor {
|
||||
type
|
||||
label
|
||||
description
|
||||
required
|
||||
options
|
||||
champDescriptors {
|
||||
type
|
||||
label
|
||||
description
|
||||
required
|
||||
options
|
||||
}
|
||||
}
|
||||
|
||||
fragment DemarcheDescriptorFragment on DemarcheDescriptor {
|
||||
number
|
||||
title
|
||||
description
|
||||
datePublication
|
||||
service { nom organisme typeOrganisme }
|
||||
cadreJuridique
|
||||
deliberation
|
||||
dossiersCount
|
||||
revision {
|
||||
champDescriptors { ...ChampDescriptorFragment }
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace :benchmarks do
|
|||
Benchmark.bm do |x|
|
||||
x.report("Démarche 45964") { SerializerService.dossiers(p_45964) }
|
||||
x.report("Démarche 55824") { SerializerService.dossiers(p_55824) }
|
||||
x.report("Démarches publiques") { SerializerService.demarches_publiques }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue