diff options
author | Olaf Tomalka <olaf.tomalka@gmail.com> | 2016-09-06 11:53:34 +0200 |
---|---|---|
committer | Olaf Tomalka <olaf.tomalka@gmail.com> | 2016-09-07 12:55:25 -0700 |
commit | 4b98e812b29e8f9bc11d2eaa4ad0ddd474caa9a6 (patch) | |
tree | 6c00231f3c7fc5c491d39532ca75267ceac228c1 | |
parent | c0a92cb801528f00d1317b01fd8a94274552c166 (diff) | |
download | gitlab-ce-4b98e812b29e8f9bc11d2eaa4ad0ddd474caa9a6.tar.gz |
Optimized event pruning query to avoid two queries.
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | app/workers/prune_old_events_worker.rb | 13 |
2 files changed, 12 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG index 1d42acfe363..7eb535923a6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,9 +3,8 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.12.0 (unreleased) - Add ability to fork to a specific namespace using API. (ritave) - Cleanup misalignments in Issue list view !6206 - - Prune events older than 12 months. @ritave <olaf@tomalka.me> + - Prune events older than 12 months. (ritave) - Prepend blank line to `Closes` message on merge request linked to issue (lukehowell) - - Prune events older than 12 months. - Filter tags by name !6121 - Make push events have equal vertical spacing. - Add two-factor recovery endpoint to internal API !5510 diff --git a/app/workers/prune_old_events_worker.rb b/app/workers/prune_old_events_worker.rb index d75083f9ab1..5883cafe1d1 100644 --- a/app/workers/prune_old_events_worker.rb +++ b/app/workers/prune_old_events_worker.rb @@ -2,7 +2,16 @@ class PruneOldEventsWorker include Sidekiq::Worker def perform - # Contribution calendar shows maximum 12 months of events - Event.delete(Event.unscoped.where('created_at < ?', (12.months + 1.day).ago).limit(10_000).pluck(:id)) + # 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 < ?', + (12.months + 1.day).ago). + select(:id). + limit(10_000)). + delete_all end end |