Merge pull request #7903 from betagouv/small_perf_gain
perf(dossier brouillon): petites optimisations
This commit is contained in:
commit
b0831de11d
5 changed files with 15 additions and 14 deletions
|
@ -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?
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
Loading…
Reference in a new issue