From b0278397219b55c5cdf2a73c6a63c303f6f5c5a3 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 11 Oct 2024 17:13:53 +0200 Subject: [PATCH] =?UTF-8?q?fix(graphql):=20parse=5Fetablissement=5Faddress?= =?UTF-8?q?=20is=20slow=20(300ms)=20=E2=80=93=20bypasse=20it=20when=20poss?= =?UTF-8?q?ible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/graphql/types/personne_morale_type.rb | 7 +++++-- .../api/v2/graphql_controller_stored_queries_spec.rb | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/graphql/types/personne_morale_type.rb b/app/graphql/types/personne_morale_type.rb index cfa63db30..849e43f6e 100644 --- a/app/graphql/types/personne_morale_type.rb +++ b/app/graphql/types/personne_morale_type.rb @@ -124,8 +124,11 @@ module Types field :complement_adresse, String, null: true, deprecation_reason: "Utilisez le champ `address` à la place." def address - APIGeoService - .parse_etablissement_address(object) + address = object.champ&.value_json + if address.blank? || !address.key?("departement_code") + address = APIGeoService.parse_etablissement_address(object) + end + address .merge(label: object.adresse, type: "housenumber") .with_indifferent_access end diff --git a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb index f3f6c11b9..db870b996 100644 --- a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb @@ -122,8 +122,9 @@ describe API::V2::GraphqlController do end context 'with entreprise' do + let(:types_de_champ_public) { [{ type: :siret }] } let(:procedure) { create(:procedure, :published, :with_service, administrateurs: [admin], types_de_champ_public:) } - let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure) } + let(:dossier) { create(:dossier, :en_construction, :with_entreprise, :with_populated_champs, procedure: procedure) } it { expect(gql_errors).to be_nil