Merge pull request #7598 from tchak/perf-graphql-demarches-publiques
perf(graphql): benchmark demarches_publiques query
This commit is contained in:
commit
9a0b554818
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::Execution::Interpreter
|
||||||
use GraphQL::Analysis::AST
|
use GraphQL::Analysis::AST
|
||||||
use GraphQL::Schema::Timeout, max_seconds: 30
|
use GraphQL::Schema::Timeout, max_seconds: 10
|
||||||
use GraphQL::Batch
|
use GraphQL::Batch
|
||||||
use GraphQL::Backtrace
|
use GraphQL::Backtrace
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Types
|
||||||
|
|
||||||
def champ_descriptors
|
def champ_descriptors
|
||||||
if object.type_de_champ.repetition?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ module Types
|
||||||
argument :number, Int, "Numéro du groupe instructeur.", required: true
|
argument :number, Int, "Numéro du groupe instructeur.", required: true
|
||||||
end
|
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
|
def demarches_publiques
|
||||||
Procedure.opendata
|
Procedure.opendata.includes(draft_revision: :procedure, published_revision: :procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
def demarche(number:)
|
def demarche(number:)
|
||||||
|
|
|
@ -30,60 +30,21 @@ class DemarchesPubliquesExportService
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_query(cursor: nil)
|
def execute_query(cursor: nil)
|
||||||
result = API::V2::Schema.execute(query, variables: { cursor: cursor }, context: { internal_use: true })
|
@graphql_data = SerializerService.demarches_publiques(after: cursor)
|
||||||
raise DemarchesPubliquesExportService::Error.new(result["errors"]) if result["errors"]
|
rescue => e
|
||||||
@graphql_data = result["data"]
|
raise DemarchesPubliquesExportService::Error.new(e.message)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_cursor
|
def last_cursor
|
||||||
@graphql_data["demarchesPubliques"]["pageInfo"]["endCursor"]
|
@graphql_data["pageInfo"]["endCursor"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_next_page?
|
def has_next_page?
|
||||||
@graphql_data["demarchesPubliques"]["pageInfo"]["hasNextPage"]
|
@graphql_data["pageInfo"]["hasNextPage"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def demarches
|
def demarches
|
||||||
@graphql_data["demarchesPubliques"]["edges"].map { |edge| edge["node"] }
|
@graphql_data["nodes"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def jsonify(demarches)
|
def jsonify(demarches)
|
||||||
|
|
|
@ -9,6 +9,11 @@ class SerializerService
|
||||||
data && data['demarche']['dossiers']
|
data && data['demarche']['dossiers']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.demarches_publiques(after: nil)
|
||||||
|
data = execute_query('serializeDemarchesPubliques', { after: after })
|
||||||
|
data && data['demarchesPubliques']
|
||||||
|
end
|
||||||
|
|
||||||
def self.avis(avis)
|
def self.avis(avis)
|
||||||
data = execute_query('serializeAvis', { number: avis.dossier_id, id: avis.to_typed_id })
|
data = execute_query('serializeAvis', { number: avis.dossier_id, id: avis.to_typed_id })
|
||||||
data && data['dossier']['avis'].first
|
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!) {
|
query serializeDossier($number: Int!) {
|
||||||
dossier(number: $number) {
|
dossier(number: $number) {
|
||||||
...DossierFragment
|
...DossierFragment
|
||||||
|
@ -260,5 +277,34 @@ class SerializerService
|
||||||
byteSize: byteSizeBigInt
|
byteSize: byteSizeBigInt
|
||||||
contentType
|
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
|
GRAPHQL
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace :benchmarks do
|
||||||
Benchmark.bm do |x|
|
Benchmark.bm do |x|
|
||||||
x.report("Démarche 45964") { SerializerService.dossiers(p_45964) }
|
x.report("Démarche 45964") { SerializerService.dossiers(p_45964) }
|
||||||
x.report("Démarche 55824") { SerializerService.dossiers(p_55824) }
|
x.report("Démarche 55824") { SerializerService.dossiers(p_55824) }
|
||||||
|
x.report("Démarches publiques") { SerializerService.demarches_publiques }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue