perf(dossier): cache gallery attachments
This commit is contained in:
parent
c6ab05dcc5
commit
838dc0a9e3
1 changed files with 16 additions and 12 deletions
|
@ -489,20 +489,24 @@ module Instructeurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_gallery_attachments
|
def set_gallery_attachments
|
||||||
@dossier = current_instructeur.dossiers.find(params[:dossier_id])
|
gallery_attachments_ids = Rails.cache.fetch([dossier, "gallery_attachments"], expires_in: 10.minutes) do
|
||||||
|
champs_attachments_ids = dossier
|
||||||
|
.champs
|
||||||
|
.where(type: [Champs::PieceJustificativeChamp.name, Champs::TitreIdentiteChamp.name])
|
||||||
|
.flat_map(&:piece_justificative_file)
|
||||||
|
.map(&:id)
|
||||||
|
|
||||||
champs_attachments = @dossier
|
commentaires_attachments_ids = dossier
|
||||||
.champs
|
.commentaires
|
||||||
.filter { _1.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) }
|
.includes(piece_jointe_attachments: :blob)
|
||||||
.flat_map(&:piece_justificative_file)
|
.map(&:piece_jointe)
|
||||||
|
.map(&:attachments)
|
||||||
|
.flatten
|
||||||
|
.map(&:id)
|
||||||
|
|
||||||
commentaires_attachments = @dossier
|
champs_attachments_ids + commentaires_attachments_ids
|
||||||
.commentaires
|
end
|
||||||
.map(&:piece_jointe)
|
@gallery_attachments = ActiveStorage::Attachment.where(id: gallery_attachments_ids)
|
||||||
.map(&:attachments)
|
|
||||||
.flatten
|
|
||||||
|
|
||||||
@gallery_attachments = champs_attachments + commentaires_attachments
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue