2016-09-05 04:18:08 -04:00
|
|
|
class PruneOldEventsWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2016-10-21 12:13:41 -04:00
|
|
|
include CronjobQueue
|
2016-09-05 04:18:08 -04:00
|
|
|
|
|
|
|
def perform
|
2016-09-06 05:53:34 -04: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 09:48:12 -04:00
|
|
|
(12.months + 1.day).ago)
|
|
|
|
.select(:id)
|
|
|
|
.limit(10_000))
|
|
|
|
.delete_all
|
2016-09-05 04:18:08 -04:00
|
|
|
end
|
|
|
|
end
|