Merge pull request #7903 from betagouv/small_perf_gain

perf(dossier brouillon): petites optimisations
This commit is contained in:
LeSim 2022-10-13 22:42:48 +02:00 committed by GitHub
commit b0831de11d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 14 deletions

View file

@ -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?

View file

@ -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?

View file

@ -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

View file

@ -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

View file

@ -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 }