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
|
end
|
||||||
|
|
||||||
def submit_brouillon
|
def submit_brouillon
|
||||||
@dossier = dossier_with_champs
|
@dossier = dossier_with_champs(pj_template: false)
|
||||||
errors = submit_dossier_and_compute_errors
|
errors = submit_dossier_and_compute_errors
|
||||||
|
|
||||||
if errors.blank?
|
if errors.blank?
|
||||||
|
@ -209,7 +209,7 @@ module Users
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@dossier = dossier_with_champs
|
@dossier = dossier_with_champs(pj_template: false)
|
||||||
errors = update_dossier_and_compute_errors
|
errors = update_dossier_and_compute_errors
|
||||||
|
|
||||||
if errors.present?
|
if errors.present?
|
||||||
|
@ -409,8 +409,8 @@ module Users
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def dossier_with_champs
|
def dossier_with_champs(pj_template: true)
|
||||||
DossierPreloader.load_one(dossier)
|
DossierPreloader.load_one(dossier, pj_template:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_change_groupe_instructeur?
|
def should_change_groupe_instructeur?
|
||||||
|
|
|
@ -198,7 +198,7 @@ class Champ < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def conditional?
|
def conditional?
|
||||||
type_de_champ.condition.present?
|
type_de_champ.read_attribute_before_type_cast('condition').present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible?
|
def visible?
|
||||||
|
|
|
@ -17,8 +17,8 @@ class DossierPreloader
|
||||||
dossiers
|
dossiers
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load_one(dossier)
|
def self.load_one(dossier, pj_template: false)
|
||||||
DossierPreloader.new([dossier]).all(pj_template: true).first
|
DossierPreloader.new([dossier]).all(pj_template: pj_template).first
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -29,15 +29,16 @@ class Logic::ChampValue < Logic::Term
|
||||||
return nil if !targeted_champ.visible?
|
return nil if !targeted_champ.visible?
|
||||||
return nil if targeted_champ.blank?
|
return nil if targeted_champ.blank?
|
||||||
|
|
||||||
case type_de_champ(champs.map(&:type_de_champ)).type_champ
|
# on dépense 22ms ici, à cause du map, mais on doit pouvoir passer par un champ type
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:yes_no),
|
case targeted_champ.type
|
||||||
MANAGED_TYPE_DE_CHAMP.fetch(:checkbox)
|
when "Champs::YesNoChamp",
|
||||||
|
"Champs::CheckboxChamp"
|
||||||
targeted_champ.true?
|
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
|
targeted_champ.for_api
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list)
|
when "Champs::DropDownListChamp"
|
||||||
targeted_champ.selected
|
targeted_champ.selected
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list)
|
when "Champs::MultipleDropDownListChamp"
|
||||||
targeted_champ.selected_options
|
targeted_champ.selected_options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe DossierPreloader do
|
||||||
let(:first_child) { subject.champs.second.champs.first }
|
let(:first_child) { subject.champs.second.champs.first }
|
||||||
|
|
||||||
describe 'all' do
|
describe 'all' do
|
||||||
subject { DossierPreloader.load_one(dossier) }
|
subject { DossierPreloader.load_one(dossier, pj_template: true) }
|
||||||
|
|
||||||
before { subject }
|
before { subject }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue