2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-05 08:18:08 +00:00
|
|
|
class PruneOldEventsWorker
|
2017-11-28 16:08:30 +00:00
|
|
|
include ApplicationWorker
|
2016-10-21 16:13:41 +00:00
|
|
|
include CronjobQueue
|
2016-09-05 08:18:08 +00:00
|
|
|
|
|
|
|
def perform
|
2016-09-06 09:53:34 +00:00
|
|
|
# Contribution calendar shows maximum 12 months of events.
|
|
|
|
# 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 < ?',
|
2017-06-21 13:48:12 +00:00
|
|
|
(12.months + 1.day).ago)
|
|
|
|
.select(:id)
|
|
|
|
.limit(10_000))
|
|
|
|
.delete_all
|
2016-09-05 08:18:08 +00:00
|
|
|
end
|
|
|
|
end
|