remove one sql query
This commit is contained in:
parent
41569efe9d
commit
5e180268cd
1 changed files with 3 additions and 2 deletions
|
@ -690,12 +690,13 @@ class Procedure < ApplicationRecord
|
|||
|
||||
def average_dossier_weight
|
||||
if dossiers.termine.any?
|
||||
dossiers_sample = dossiers.termine.limit(100)
|
||||
total_size = Champ
|
||||
.includes(piece_justificative_file_attachment: :blob)
|
||||
.where(type: "Champs::PieceJustificativeChamp", dossier: dossiers.termine.limit(100))
|
||||
.where(type: "Champs::PieceJustificativeChamp", dossier: dossiers_sample)
|
||||
.sum('active_storage_blobs.byte_size')
|
||||
|
||||
total_size / dossiers.termine.limit(100).count
|
||||
total_size / dossiers_sample.length
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue