Module: Gitlab::Database::AsyncIndexes

Defined in:
lib/gitlab/database/async_indexes.rb,
lib/gitlab/database/async_indexes/index_base.rb,
lib/gitlab/database/async_indexes/index_creator.rb,
lib/gitlab/database/async_indexes/index_destructor.rb,
lib/gitlab/database/async_indexes/migration_helpers.rb,
lib/gitlab/database/async_indexes/postgres_async_index.rb

Defined Under Namespace

Modules: MigrationHelpers Classes: IndexBase, IndexCreator, IndexDestructor, PostgresAsyncIndex

Constant Summary collapse

DEFAULT_INDEXES_PER_INVOCATION =
2

Class Method Summary collapse

Class Method Details

.create_pending_indexes!(how_many: DEFAULT_INDEXES_PER_INVOCATION) ⇒ Object



8
9
10
11
12
# File 'lib/gitlab/database/async_indexes.rb', line 8

def self.create_pending_indexes!(how_many: DEFAULT_INDEXES_PER_INVOCATION)
  PostgresAsyncIndex.to_create.order(:id).limit(how_many).each do |async_index|
    IndexCreator.new(async_index).perform
  end
end

.drop_pending_indexes!(how_many: DEFAULT_INDEXES_PER_INVOCATION) ⇒ Object



14
15
16
17
18
# File 'lib/gitlab/database/async_indexes.rb', line 14

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

.execute_pending_actions!(how_many: DEFAULT_INDEXES_PER_INVOCATION) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/gitlab/database/async_indexes.rb', line 20

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