amelioration(data): re-associe les anciennes invitation avec un nouveau targeted_user_link pour concerver des données homogènes

This commit is contained in:
Martin 2023-01-31 17:09:36 +01:00
parent 70e3d5a30c
commit bf839d61a0

View file

@ -5,14 +5,32 @@ namespace :after_party do
# Put your task implementation HERE. # Put your task implementation HERE.
invalid_invites = Invite.where('invites.created_at > ?', 1.month.ago) invalid_invites_to_refresh = Invite.where('invites.created_at > ?', 1.month.ago)
.joins(:targeted_user_link) .joins(:targeted_user_link)
.where(targeted_user_link: { target_model_type: 'Avis' }) .where(targeted_user_link: { target_model_type: 'Avis' })
progress = ProgressReport.new(invalid_invites.count) invalid_invites_to_silence = Invite.where('invites.created_at <= ?', 1.month.ago)
invalid_invites.find_each do |invite| .joins(:targeted_user_link)
.where(targeted_user_link: { target_model_type: 'Avis' })
progress = ProgressReport.new(invalid_invites_to_refresh.count + invalid_invites_to_silence.count)
invalid_invites_to_refresh.find_each do |invite|
invite.send_notification invite.send_notification
progress.inc progress.inc
end end
invalid_invites_to_silence.find_each do |invite|
if invite.user.present?
invite.create_targeted_user_link(target_context: 'invite',
target_model: invite,
user: invite.user)
else
invite.create_targeted_user_link(target_context: 'invite',
target_model: invite)
end
progress.inc
end
progress.finish progress.finish
# Update task as completed. If you remove the line below, the task will # Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run). # run with every deploy (or every time you call after_party:run).