diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index 7e0198f50..697a7bdd9 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -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 diff --git a/app/graphql/types/champ_descriptor_type.rb b/app/graphql/types/champ_descriptor_type.rb index fcefc8010..9d01a8ae8 100644 --- a/app/graphql/types/champ_descriptor_type.rb +++ b/app/graphql/types/champ_descriptor_type.rb @@ -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 diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 6e8c3ce14..3654baf99 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -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:) diff --git a/app/services/demarches_publiques_export_service.rb b/app/services/demarches_publiques_export_service.rb index 2508c1e12..d210bc2c0 100644 --- a/app/services/demarches_publiques_export_service.rb +++ b/app/services/demarches_publiques_export_service.rb @@ -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) diff --git a/app/services/serializer_service.rb b/app/services/serializer_service.rb index 68de41017..eea18aea0 100644 --- a/app/services/serializer_service.rb +++ b/app/services/serializer_service.rb @@ -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 diff --git a/lib/tasks/benchmarks.rake b/lib/tasks/benchmarks.rake index 2cce6675d..a8680b730 100644 --- a/lib/tasks/benchmarks.rake +++ b/lib/tasks/benchmarks.rake @@ -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