From 73b4ee64e6d0e3dc8ee3c6ce6b4d806383888e35 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 13 Oct 2022 15:01:46 +0200 Subject: [PATCH 1/3] perf(champ_value): use champ_type instead of tdc.type_champ, -22ms --- app/models/logic/champ_value.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index 70db5a24b..07d26af01 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -29,15 +29,16 @@ class Logic::ChampValue < Logic::Term return nil if !targeted_champ.visible? return nil if targeted_champ.blank? - case type_de_champ(champs.map(&:type_de_champ)).type_champ - when MANAGED_TYPE_DE_CHAMP.fetch(:yes_no), - MANAGED_TYPE_DE_CHAMP.fetch(:checkbox) + # on dépense 22ms ici, à cause du map, mais on doit pouvoir passer par un champ type + case targeted_champ.type + when "Champs::YesNoChamp", + "Champs::CheckboxChamp" targeted_champ.true? - when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number) + when "Champs::IntegerNumberChamp", "Champs::DecimalNumberChamp" targeted_champ.for_api - when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list) + when "Champs::DropDownListChamp" targeted_champ.selected - when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list) + when "Champs::MultipleDropDownListChamp" targeted_champ.selected_options end end From f8ee6386b96fc64502573e40a0db3f7a543f8ab9 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 13 Oct 2022 12:30:45 +0200 Subject: [PATCH 2/3] perf(champ): check condition.present? without json deserializationl, -6ms --- app/models/champ.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index 6cf371393..e5c1a72b1 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -198,7 +198,7 @@ class Champ < ApplicationRecord end def conditional? - type_de_champ.condition.present? + type_de_champ.read_attribute_before_type_cast('condition').present? end def visible? From 40a3fff5938486d2aabf0d9ff0b7e6134157f6b7 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 13 Oct 2022 15:54:38 +0200 Subject: [PATCH 3/3] perf(dossiers_controller): do not load pj template in update, -10ms --- app/controllers/users/dossiers_controller.rb | 8 ++++---- app/models/dossier_preloader.rb | 4 ++-- spec/models/dossier_preloader_spec.rb | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 6c36aa7be..7b0d52996 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -160,7 +160,7 @@ module Users end def submit_brouillon - @dossier = dossier_with_champs + @dossier = dossier_with_champs(pj_template: false) errors = submit_dossier_and_compute_errors if errors.blank? @@ -209,7 +209,7 @@ module Users end def update - @dossier = dossier_with_champs + @dossier = dossier_with_champs(pj_template: false) errors = update_dossier_and_compute_errors if errors.present? @@ -409,8 +409,8 @@ module Users end end - def dossier_with_champs - DossierPreloader.load_one(dossier) + def dossier_with_champs(pj_template: true) + DossierPreloader.load_one(dossier, pj_template:) end def should_change_groupe_instructeur? diff --git a/app/models/dossier_preloader.rb b/app/models/dossier_preloader.rb index 8e1d0f113..3d4a0ac2a 100644 --- a/app/models/dossier_preloader.rb +++ b/app/models/dossier_preloader.rb @@ -17,8 +17,8 @@ class DossierPreloader dossiers end - def self.load_one(dossier) - DossierPreloader.new([dossier]).all(pj_template: true).first + def self.load_one(dossier, pj_template: false) + DossierPreloader.new([dossier]).all(pj_template: pj_template).first end private diff --git a/spec/models/dossier_preloader_spec.rb b/spec/models/dossier_preloader_spec.rb index f1de07b97..b2bcba549 100644 --- a/spec/models/dossier_preloader_spec.rb +++ b/spec/models/dossier_preloader_spec.rb @@ -11,7 +11,7 @@ describe DossierPreloader do let(:first_child) { subject.champs.second.champs.first } describe 'all' do - subject { DossierPreloader.load_one(dossier) } + subject { DossierPreloader.load_one(dossier, pj_template: true) } before { subject }