Merge pull request #7103 from betagouv/faster_archive

Faster archive
This commit is contained in:
mfo 2022-04-01 17:10:14 +02:00 committed by GitHub
commit 6a7a44dd07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,16 +4,14 @@ class PiecesJustificativesService
pjs_commentaires = pjs_for_commentaires(dossier)
pjs_dossier = pjs_for_dossier(dossier, for_expert)
(pjs_champs + pjs_commentaires + pjs_dossier)
.filter(&:attached?)
pjs_champs + pjs_commentaires + pjs_dossier.filter(&:attached?)
end
def self.liste_pieces_justificatives(dossier)
pjs_champs = pjs_for_champs(dossier)
pjs_commentaires = pjs_for_commentaires(dossier)
(pjs_champs + pjs_commentaires)
.filter(&:attached?)
pjs_champs + pjs_commentaires
end
def self.pieces_justificatives_total_size(dossier)
@ -121,21 +119,27 @@ class PiecesJustificativesService
private
def self.pjs_for_champs(dossier, for_expert = false)
allowed_champs = for_expert ? dossier.champs : dossier.champs + dossier.champs_private
champs = Champ
.joins(:piece_justificative_file_attachment)
.where(type: "Champs::PieceJustificativeChamp", dossier: dossier)
allowed_child_champs = allowed_champs
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
.flat_map(&:champs)
if for_expert
champs = champs.where(private: false)
end
(allowed_champs + allowed_child_champs)
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
.map(&:piece_justificative_file)
ActiveStorage::Attachment
.includes(:blob)
.where(record_type: "Champ", record_id: champs.ids)
end
def self.pjs_for_commentaires(dossier)
dossier
.commentaires
.map(&:piece_jointe)
commentaires = Commentaire
.joins(:piece_jointe_attachment)
.where(dossier: dossier)
ActiveStorage::Attachment
.includes(:blob)
.where(record_type: "Commentaire", record_id: commentaires.ids)
end
def self.pjs_for_dossier(dossier, for_expert = false)