perf(zip): give champ to avoid seeking stable_id

This commit is contained in:
simon lehericey 2024-05-17 17:01:41 +02:00
parent a7e29c4ea6
commit ca12a56e6a
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5

View file

@ -45,10 +45,10 @@ class ExportTemplate < ApplicationRecord
end end
end end
def attachment_and_path(dossier, attachment, index: 0, row_index: nil) def attachment_and_path(dossier, attachment, index: 0, row_index: nil, champ: nil)
[ [
attachment, attachment,
path(dossier, attachment, index, row_index) path(dossier, attachment, index, row_index, champ)
] ]
end end
@ -116,7 +116,7 @@ class ExportTemplate < ApplicationRecord
"#{render_attributes_for(content["pdf_name"], dossier)}.pdf" "#{render_attributes_for(content["pdf_name"], dossier)}.pdf"
end end
def path(dossier, attachment, index, row_index) def path(dossier, attachment, index, row_index, champ)
if attachment.name == 'pdf_export_for_instructeur' if attachment.name == 'pdf_export_for_instructeur'
return export_path(dossier) return export_path(dossier)
end end
@ -130,15 +130,14 @@ class ExportTemplate < ApplicationRecord
'avis' 'avis'
else else
# for attachment # for attachment
return attachment_path(dossier, attachment, index, row_index) return attachment_path(dossier, attachment, index, row_index, champ)
end end
File.join(folder(dossier), dir_path, attachment.filename.to_s) File.join(folder(dossier), dir_path, attachment.filename.to_s)
end end
def attachment_path(dossier, attachment, index, row_index) def attachment_path(dossier, attachment, index, row_index, champ)
type_de_champ_id = dossier.champs.find(attachment.record_id).type_de_champ_id stable_id = champ.stable_id
stable_id = TypeDeChamp.find(type_de_champ_id).stable_id
tiptap_pj = content["pjs"].find { |pj| pj["stable_id"] == stable_id.to_s } tiptap_pj = content["pjs"].find { |pj| pj["stable_id"] == stable_id.to_s }
if tiptap_pj if tiptap_pj
File.join(folder(dossier), tiptap_convert_pj(dossier, stable_id, attachment) + suffix(attachment, index, row_index)) File.join(folder(dossier), tiptap_convert_pj(dossier, stable_id, attachment) + suffix(attachment, index, row_index))