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:
clemkeirua 2020-07-28 17:15:43 +02:00 committed by Christophe Robillard
parent 03e3e8fb1c
commit 153c6aebd7

View 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