Class: Ci::NamespaceMirror

Inherits:
ApplicationRecord show all
Includes:
FromUnion
Defined in:
app/models/ci/namespace_mirror.rb

Overview

This model represents a record in a shadow table of the main database's namespaces table. It allows us to navigate the namespace hierarchy on the ci database without resorting to a JOIN.

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.sync!(event) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/ci/namespace_mirror.rb', line 40

def sync!(event)
  namespace = event.namespace
  traversal_ids = namespace.self_and_ancestor_ids(hierarchy_order: :desc)

  upsert({ namespace_id: event.namespace_id, traversal_ids: traversal_ids },
         unique_by: :namespace_id)

  # It won't be necessary once we remove `sync_traversal_ids`.
  # More info: https://gitlab.com/gitlab-org/gitlab/-/issues/347541
  sync_children_namespaces!(event.namespace_id, traversal_ids)
end