summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/reindexing.rb
blob: 841e04ccbd1ca3f2c268cf75c03a597a5e9153ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module Gitlab
  module Database
    module Reindexing
      # Number of indexes to reindex per invocation
      DEFAULT_INDEXES_PER_INVOCATION = 2

      SUPPORTED_TYPES = %w(btree gist).freeze

      # candidate_indexes: Array of Gitlab::Database::PostgresIndex
      def self.perform(candidate_indexes, how_many: DEFAULT_INDEXES_PER_INVOCATION)
        IndexSelection.new(candidate_indexes).take(how_many).each do |index|
          Coordinator.new(index).perform
        end
      end

      def self.candidate_indexes
        Gitlab::Database::PostgresIndex
          .not_match("#{ReindexConcurrently::TEMPORARY_INDEX_PATTERN}$")
          .reindexing_support
      end
    end
  end
end