2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-09-05 04:18:08 -04:00
|
|
|
def perform
|
2018-10-06 06:09:49 -04:00
|
|
|
# Contribution calendar shows maximum 12 months of events, we retain 2 years for data integrity.
|
|
|
|
# Double nested query is used because MySQL doesn't allow DELETE subqueries on the same table.
|
2016-09-06 05:53:34 -04:00
|
|
|
Event.unscoped.where(
|
|
|
|
'(id IN (SELECT id FROM (?) ids_to_remove))',
|
|
|
|
Event.unscoped.where(
|
|
|
|
'created_at < ?',
|
2018-10-05 09:22:58 -04:00
|
|
|
(2.years + 1.day).ago)
|
2017-06-21 09:48:12 -04:00
|
|
|
.select(:id)
|
|
|
|
.limit(10_000))
|
|
|
|
.delete_all
|
2016-09-05 04:18:08 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-09-05 04:18:08 -04:00
|
|
|
end
|