diff options
-rw-r--r-- | app/workers/prune_old_events_worker.rb | 7 | ||||
-rw-r--r-- | changelogs/unreleased/copy-changes-for-abuse-clarity.yml | 5 | ||||
-rw-r--r-- | doc/api/events.md | 2 | ||||
-rw-r--r-- | spec/workers/prune_old_events_worker_spec.rb | 20 |
4 files changed, 22 insertions, 12 deletions
diff --git a/app/workers/prune_old_events_worker.rb b/app/workers/prune_old_events_worker.rb index d44ad0d8030..dc4b7670131 100644 --- a/app/workers/prune_old_events_worker.rb +++ b/app/workers/prune_old_events_worker.rb @@ -6,14 +6,13 @@ class PruneOldEventsWorker # rubocop: disable CodeReuse/ActiveRecord def perform - # Contribution calendar shows maximum 12 months of events. - # Double nested query is used because MySQL doesn't allow DELETE subqueries - # on the same table. + # 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. Event.unscoped.where( '(id IN (SELECT id FROM (?) ids_to_remove))', Event.unscoped.where( 'created_at < ?', - (12.months + 1.day).ago) + (2.years + 1.day).ago) .select(:id) .limit(10_000)) .delete_all diff --git a/changelogs/unreleased/copy-changes-for-abuse-clarity.yml b/changelogs/unreleased/copy-changes-for-abuse-clarity.yml new file mode 100644 index 00000000000..00d9fec5e42 --- /dev/null +++ b/changelogs/unreleased/copy-changes-for-abuse-clarity.yml @@ -0,0 +1,5 @@ +--- +title: Increased retained event data by extending events pruner timeframe to 2 years +merge_request: 22145 +author: +type: changed diff --git a/doc/api/events.md b/doc/api/events.md index fb5ebb71a86..cd84b32029e 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -44,7 +44,7 @@ YYYY-MM-DD ### Event Time Period Limit -GitLab removes events older than 1 year from the events table for performance reasons. The range of 1 year was chosen because user contribution calendars only show contributions of the past year. +GitLab removes events older than 2 years from the events table for performance reasons. ## List currently authenticated user's events diff --git a/spec/workers/prune_old_events_worker_spec.rb b/spec/workers/prune_old_events_worker_spec.rb index ea974355050..b999a6fd5b6 100644 --- a/spec/workers/prune_old_events_worker_spec.rb +++ b/spec/workers/prune_old_events_worker_spec.rb @@ -4,23 +4,29 @@ describe PruneOldEventsWorker do describe '#perform' do let(:user) { create(:user) } - let!(:expired_event) { create(:event, :closed, author: user, created_at: 13.months.ago) } - let!(:not_expired_event) { create(:event, :closed, author: user, created_at: 1.day.ago) } - let!(:exactly_12_months_event) { create(:event, :closed, author: user, created_at: 12.months.ago) } + let!(:expired_event) { create(:event, :closed, author: user, created_at: 25.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) } - it 'prunes events older than 12 months' do + it 'prunes events older than 2 years' do expect { subject.perform }.to change { Event.count }.by(-1) expect(Event.find_by(id: expired_event.id)).to be_nil end it 'leaves fresh events' do subject.perform - expect(not_expired_event.reload).to be_present + expect(not_expired_1_day_event.reload).to be_present end - it 'leaves events from exactly 12 months ago' do + it 'leaves events from 13 months ago' do subject.perform - expect(exactly_12_months_event).to be_present + expect(not_expired_13_month_event.reload).to be_present + end + + it 'leaves events from 2 years ago' do + subject.perform + expect(not_expired_2_years_event).to be_present end end end |