Commit 79f56e89 authored by Imre Farkas's avatar Imre Farkas Committed by Thong Kuah

Extend Events lifetime to 3 years instead of 2

We eventually want to avoid deleting any Events, see
https://gitlab.com/gitlab-org/gitlab/issues/24538.
parent 6b63cb94
......@@ -6,13 +6,13 @@ class PruneOldEventsWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform
# Contribution calendar shows maximum 12 months of events, we retain 2 years for data integrity.
# 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 < ?',
(2.years + 1.day).ago)
(3.years + 1.day).ago)
.select(:id)
.limit(10_000))
.delete_all
......
......@@ -6,12 +6,12 @@ describe PruneOldEventsWorker do
describe '#perform' do
let(:user) { create(:user) }
let!(:expired_event) { create(:event, :closed, author: user, created_at: 25.months.ago) }
let!(:expired_event) { create(:event, :closed, author: user, created_at: 37.months.ago) }
let!(:not_expired_1_day_event) { create(:event, :closed, author: user, created_at: 1.day.ago) }
let!(:not_expired_13_month_event) { create(:event, :closed, author: user, created_at: 13.months.ago) }
let!(:not_expired_2_years_event) { create(:event, :closed, author: user, created_at: 2.years.ago) }
let!(:not_expired_3_years_event) { create(:event, :closed, author: user, created_at: 3.years.ago) }
it 'prunes events older than 2 years' do
it 'prunes events older than 3 years' do
expect { subject.perform }.to change { Event.count }.by(-1)
expect(Event.find_by(id: expired_event.id)).to be_nil
end
......@@ -26,9 +26,9 @@ describe PruneOldEventsWorker do
expect(not_expired_13_month_event.reload).to be_present
end
it 'leaves events from 2 years ago' do
it 'leaves events from 3 years ago' do
subject.perform
expect(not_expired_2_years_event).to be_present
expect(not_expired_3_years_event).to be_present
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment