An error occurred while fetching the assigned milestone of the selected merge_request.
Traversal ids queries
7 unresolved threads
Closes #230456 (closed)
Currently to query the namespace hierarchy we must use recursive methods through Gitlab::ObjectHierarchy
. We can query the namespace hierarchy a lot faster and easier if we store the path from the root ancestor to each namespace as an attribute on the namespace. We will store this on a new traversal_id
attribute on Namespaces
.
Say we have this Namespace hierarchy...
graph TD;
gitlab-->backend;
backend-->create;
backend-->manage;
create-->source;
manage-->access;
gitlab-->frontend;
Then the path from gitlab
to access
is gitlab / backend / manage / access
. The path from gitlab
to source
is gitlab / backend / create / source
.
We can use this structure for fast queries. If the current namespace is backend
then all our descendants match the path gitlab / backend / *
, all our ancestors match the path * / backend
, and everyone in the same Namespace hierarchy matches gitlab / *
.
We store that path using an array of Namespace ids in a new column on Namespace called traversal_ids
.
The recursive Namespace query methods have been moved to a module at app/models/concerns/namespace/recursive_traversal.rb
. Feature flags have been included to toggle between using recursive and linear querying methods.
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
@gitlab-com/gl-security/appsec