Skip to content
Snippets Groups Projects

Use a separate table for storing push events

Merged Yorick Peterse requested to merge split-events-into-push-events into master
Compare and Show latest version
2 files
+ 14
11
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,6 +5,7 @@ class ScheduleEventMigrations < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
BUFFER_SIZE = 100
disable_ddl_transaction!
@@ -15,21 +16,23 @@ class Event < ActiveRecord::Base
end
def up
Event.each_batch(of: 10_000) do |outer_relation|
ranges = []
jobs = []
outer_relation.each_batch(of: 100) do |relation|
min, max = relation.pluck('MIN(id), MAX(id)').first
Event.each_batch(of: 100) do |relation|
min, max = relation.pluck('MIN(id), MAX(id)').first
ranges << [min, max]
if jobs.length == BUFFER_SIZE
# We push 100 jobs at a time to reduce the time spent in Sidekiq/Redis
# operations. We're using this buffer based approach so we don't need to
# run additional queries for every range.
BackgroundMigrationWorker.perform_bulk(jobs)
jobs.clear
end
jobs = ranges.map do |range|
['MigrateEventsToPushEventPayloads', range]
end
BackgroundMigrationWorker.perform_bulk(jobs)
jobs << ['MigrateEventsToPushEventPayloads', [min, max]]
end
BackgroundMigrationWorker.perform_bulk(jobs) unless jobs.empty?
end
def down
Loading