summaryrefslogtreecommitdiff
path: root/app/workers/prune_old_events_worker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/prune_old_events_worker.rb')
-rw-r--r--app/workers/prune_old_events_worker.rb16
1 files changed, 5 insertions, 11 deletions
diff --git a/app/workers/prune_old_events_worker.rb b/app/workers/prune_old_events_worker.rb
index f421e8dbf59..1d915832833 100644
--- a/app/workers/prune_old_events_worker.rb
+++ b/app/workers/prune_old_events_worker.rb
@@ -6,18 +6,12 @@ class PruneOldEventsWorker
feature_category_not_owned!
- # rubocop: disable CodeReuse/ActiveRecord
+ DELETE_LIMIT = 10_000
+
def perform
# Contribution calendar shows maximum 12 months of events, we retain 3 years for data integrity.
- # Double nested query is used because MySQL doesn't allow DELETE subqueries on the same table.
- Event.unscoped.where(
- '(id IN (SELECT id FROM (?) ids_to_remove))',
- Event.unscoped.where(
- 'created_at < ?',
- (3.years + 1.day).ago)
- .select(:id)
- .limit(10_000))
- .delete_all
+ cutoff_date = (3.years + 1.day).ago
+
+ Event.unscoped.created_before(cutoff_date).delete_with_limit(DELETE_LIMIT)
end
- # rubocop: enable CodeReuse/ActiveRecord
end