From 4641be3727dec5cb24cd1fab6f582b8d231931b0 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Tue, 7 Nov 2023 16:53:56 +0100 Subject: [PATCH] Simplify if --- app/jobs/remove_activities_job.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/jobs/remove_activities_job.rb b/app/jobs/remove_activities_job.rb index 7353fbe33f..14f7a8c612 100644 --- a/app/jobs/remove_activities_job.rb +++ b/app/jobs/remove_activities_job.rb @@ -22,18 +22,19 @@ def perform end Exercise.where(status: 'removed').where('updated_at < ?', 1.month.ago).find_each do |activity| - if activity.draft? || - (activity.series_memberships.empty? && - (activity.submissions.empty? || - (activity.submissions.count < 25 && activity.submissions.reorder(:created_at).last.created_at < 1.month.ago))) - # destroy submissions first explicitly, as they are dependent: :restrict_with_error - activity.submissions.destroy_all + unless activity.draft? + next if activity.series_memberships.present? + next if activity.submissions.count >= 25 + next if activity.submissions.present? && activity.submissions.reorder(:created_at).last.created_at > 1.month.ago + end - # destroy series memberships first explicitly, as they are dependent: :restrict_with_error - activity.series_memberships.destroy_all + # destroy submissions first explicitly, as they are dependent: :restrict_with_error + activity.submissions.destroy_all - activity.destroy - end + # destroy series memberships first explicitly, as they are dependent: :restrict_with_error + activity.series_memberships.destroy_all + + activity.destroy end # rerun this job in 1 month