Class: Gitlab::BackgroundMigration::BackfillProjectRepositories::ShardFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/backfill_project_repositories.rb

Overview

Class that will find or create the shard by name. There is only a small set of shards, which would not change quickly, so look them up from memory instead of hitting the DB each time.

Instance Method Summary collapse

Instance Method Details

#find_shard_id(name) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/background_migration/backfill_project_repositories.rb', line 20

def find_shard_id(name)
  shard_id = shards.fetch(name, nil)
  return shard_id if shard_id.present?

  Shard.transaction(requires_new: true) do
    create!(name)
  end
rescue ActiveRecord::RecordNotUnique
  reload!
  retry
end