debian-mirror-gitlab/app/models/shard.rb

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

24 lines
778 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class Shard < ApplicationRecord
2018-12-13 13:39:08 +05:30
# Store shard names from the configuration file in the database. This is not a
# list of active shards - we just want to assign an immutable, unique ID to
# every shard name for easy indexing / referencing.
def self.populate!
return unless table_exists?
# The GitLab config does not change for the lifecycle of the process
in_config = Gitlab.config.repositories.storages.keys.map(&:to_s)
in_db = all.pluck(:name)
# This may race with other processes creating shards at the same time, but
# `by_name` will handle that correctly
missing = in_config - in_db
missing.map { |name| by_name(name) }
end
def self.by_name(name)
2021-11-11 11:23:49 +05:30
safe_find_or_create_by(name: name)
2018-12-13 13:39:08 +05:30
end
end