Skip to content

Commit

Permalink
Simplify if
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Nov 7, 2023
1 parent e7527aa commit 4641be3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions app/jobs/remove_activities_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ def perform
end

Check warning on line 22 in app/jobs/remove_activities_job.rb

View check run for this annotation

Codecov / codecov/patch

app/jobs/remove_activities_job.rb#L20-L22

Added lines #L20 - L22 were not covered by tests

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

Check warning on line 29 in app/jobs/remove_activities_job.rb

View check run for this annotation

Codecov / codecov/patch

app/jobs/remove_activities_job.rb#L24-L29

Added lines #L24 - L29 were not covered by tests

# 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

Check warning on line 32 in app/jobs/remove_activities_job.rb

View check run for this annotation

Codecov / codecov/patch

app/jobs/remove_activities_job.rb#L32

Added line #L32 was not covered by tests

activity.destroy
end
# destroy series memberships first explicitly, as they are dependent: :restrict_with_error
activity.series_memberships.destroy_all

Check warning on line 35 in app/jobs/remove_activities_job.rb

View check run for this annotation

Codecov / codecov/patch

app/jobs/remove_activities_job.rb#L35

Added line #L35 was not covered by tests

activity.destroy
end

Check warning on line 38 in app/jobs/remove_activities_job.rb

View check run for this annotation

Codecov / codecov/patch

app/jobs/remove_activities_job.rb#L37-L38

Added lines #L37 - L38 were not covered by tests

# rerun this job in 1 month
Expand Down

0 comments on commit 4641be3

Please sign in to comment.