add temp job to set last_updated_at_* values for dossier
Co-authored-by: Christophe Robillard <christophe.robillard@beta.gouv.fr>
This commit is contained in:
parent
03e3e8fb1c
commit
153c6aebd7
1 changed files with 27 additions and 0 deletions
27
app/jobs/tmp_set_dossiers_last_updated_at_job.rb
Normal file
27
app/jobs/tmp_set_dossiers_last_updated_at_job.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
class TmpSetDossiersLastUpdatedAtJob < ApplicationJob
|
||||
def perform(except)
|
||||
dossiers = Dossier.where
|
||||
.not(id: except)
|
||||
.where(last_champ_updated_at: nil)
|
||||
.includes(:champs, :avis, :commentaires)
|
||||
.limit(100)
|
||||
|
||||
dossiers.find_each do |dossier|
|
||||
last_commentaire_updated_at = dossier.commentaires.maximum(:updated_at)
|
||||
last_avis_updated_at = dossier.avis.maximum(:updated_at)
|
||||
last_champ_updated_at = dossier.champs.maximum(:updated_at)
|
||||
last_champ_private_updated_at = dossier.champs_private.maximum(:updated_at)
|
||||
dossier.update_columns(
|
||||
last_commentaire_updated_at: last_commentaire_updated_at,
|
||||
last_avis_updated_at: last_avis_updated_at,
|
||||
last_champ_updated_at: last_champ_updated_at,
|
||||
last_champ_private_updated_at: last_champ_private_updated_at
|
||||
)
|
||||
except << dossier.id
|
||||
end
|
||||
|
||||
if dossiers.where.not(id: except).exists?
|
||||
TmpSetDossiersLastUpdatedAtJob.perform_later(except)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue