debian-mirror-gitlab/lib/gitlab/database/async_indexes.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
module Gitlab
module Database
module AsyncIndexes
DEFAULT_INDEXES_PER_INVOCATION = 2
def self.create_pending_indexes!(how_many: DEFAULT_INDEXES_PER_INVOCATION)
2022-08-27 11:52:29 +05:30
PostgresAsyncIndex.to_create.order(:id).limit(how_many).each do |async_index|
2021-10-27 15:23:28 +05:30
IndexCreator.new(async_index).perform
end
end
2022-08-27 11:52:29 +05:30
def self.drop_pending_indexes!(how_many: DEFAULT_INDEXES_PER_INVOCATION)
PostgresAsyncIndex.to_drop.order(:id).limit(how_many).each do |async_index|
IndexDestructor.new(async_index).perform
end
end
2023-04-23 21:23:45 +05:30
def self.execute_pending_actions!(how_many: DEFAULT_INDEXES_PER_INVOCATION)
queue_ids = PostgresAsyncIndex.ordered.limit(how_many).pluck(:id)
removal_actions = PostgresAsyncIndex.where(id: queue_ids).to_drop.ordered
creation_actions = PostgresAsyncIndex.where(id: queue_ids).to_create.ordered
removal_actions.each { |async_index| IndexDestructor.new(async_index).perform }
creation_actions.each { |async_index| IndexCreator.new(async_index).perform }
end
2021-10-27 15:23:28 +05:30
end
end
end