refactor: memoize flat_tags
This commit is contained in:
parent
e0c867f222
commit
d60e7906e0
2 changed files with 9 additions and 7 deletions
|
@ -283,17 +283,19 @@ module TagsSubstitutionConcern
|
|||
|
||||
@escape_unsafe_tags = escape
|
||||
|
||||
flat_tags = available_tags(dossier).each_with_object({}) do |tags, result|
|
||||
valid_tags = tags_for_dossier_state(tags)
|
||||
if @flat_tags.nil?
|
||||
@flat_tags = available_tags(dossier).each_with_object({}) do |tags, result|
|
||||
valid_tags = tags_for_dossier_state(tags)
|
||||
|
||||
valid_tags.each do |tag|
|
||||
result[tag[:id]] = tag
|
||||
valid_tags.each do |tag|
|
||||
result[tag[:id]] = tag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tags_and_libelles.each_with_object({}) do |(tag_id, libelle), substitutions|
|
||||
substitutions[tag_id] = if flat_tags[tag_id].present?
|
||||
replace_tag(flat_tags[tag_id], dossier)
|
||||
substitutions[tag_id] = if @flat_tags[tag_id].present?
|
||||
replace_tag(@flat_tags[tag_id], dossier)
|
||||
else # champ not in dossier, for example during preview on draft revision
|
||||
libelle
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ describe ProcedureExportService do
|
|||
subject
|
||||
end
|
||||
|
||||
expect(sql_count).to eq(474)
|
||||
expect(sql_count).to eq(296)
|
||||
|
||||
dossier = dossiers.first
|
||||
|
||||
|
|
Loading…
Reference in a new issue