speed up pjs_for_champs * 10
This commit is contained in:
parent
0f83184859
commit
0555ff68cd
1 changed files with 11 additions and 11 deletions
|
@ -4,16 +4,14 @@ class PiecesJustificativesService
|
||||||
pjs_commentaires = pjs_for_commentaires(dossier)
|
pjs_commentaires = pjs_for_commentaires(dossier)
|
||||||
pjs_dossier = pjs_for_dossier(dossier, for_expert)
|
pjs_dossier = pjs_for_dossier(dossier, for_expert)
|
||||||
|
|
||||||
(pjs_champs + pjs_commentaires + pjs_dossier)
|
pjs_champs + (pjs_commentaires + pjs_dossier).filter(&:attached?)
|
||||||
.filter(&:attached?)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.liste_pieces_justificatives(dossier)
|
def self.liste_pieces_justificatives(dossier)
|
||||||
pjs_champs = pjs_for_champs(dossier)
|
pjs_champs = pjs_for_champs(dossier)
|
||||||
pjs_commentaires = pjs_for_commentaires(dossier)
|
pjs_commentaires = pjs_for_commentaires(dossier)
|
||||||
|
|
||||||
(pjs_champs + pjs_commentaires)
|
pjs_champs + pjs_commentaires.filter(&:attached?)
|
||||||
.filter(&:attached?)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pieces_justificatives_total_size(dossier)
|
def self.pieces_justificatives_total_size(dossier)
|
||||||
|
@ -121,15 +119,17 @@ class PiecesJustificativesService
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.pjs_for_champs(dossier, for_expert = false)
|
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
|
if for_expert
|
||||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
champs = champs.where(private: false)
|
||||||
.flat_map(&:champs)
|
end
|
||||||
|
|
||||||
(allowed_champs + allowed_child_champs)
|
ActiveStorage::Attachment
|
||||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
.includes(:blob)
|
||||||
.map(&:piece_justificative_file)
|
.where(record_type: "Champ", record_id: champs.ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pjs_for_commentaires(dossier)
|
def self.pjs_for_commentaires(dossier)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue