Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlaf Tomalka <olaf.tomalka@gmail.com>2016-09-06 12:53:34 +0300
committerOlaf Tomalka <olaf.tomalka@gmail.com>2016-09-07 22:55:25 +0300
commit4b98e812b29e8f9bc11d2eaa4ad0ddd474caa9a6 (patch)
tree6c00231f3c7fc5c491d39532ca75267ceac228c1 /app/workers
parentc0a92cb801528f00d1317b01fd8a94274552c166 (diff)
Optimized event pruning query to avoid two queries.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/prune_old_events_worker.rb13
1 files changed, 11 insertions, 2 deletions
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