diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-05-29 15:49:56 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-05-29 15:49:56 +0000 |
commit | 26bcef97d64f449b5073ac767c02961763c20b18 (patch) | |
tree | 4a0ba9af1b670ee1c2743ff37988799142c33ff5 /app/models/namespace.rb | |
parent | 7dc8961af99d2a30b0a3210f7a4ee43c8779c6d2 (diff) | |
parent | 27d5f99e508024b5c2fb8509f83e8e4c6a214865 (diff) | |
download | gitlab-ce-26bcef97d64f449b5073ac767c02961763c20b18.tar.gz |
Merge branch 'rework-authorizations-performance' into 'master'
Rework project authorizations and nested groups for better performance
See merge request !10885
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 4d59267f71d..aebee06d560 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -176,26 +176,20 @@ class Namespace < ActiveRecord::Base projects.with_shared_runners.any? end - # Scopes the model on ancestors of the record + # Returns all the ancestors of the current namespaces. def ancestors - if parent_id - path = route ? route.path : full_path - paths = [] + return self.class.none unless parent_id - until path.blank? - path = path.rpartition('/').first - paths << path - end - - self.class.joins(:route).where('routes.path IN (?)', paths).reorder('routes.path ASC') - else - self.class.none - end + Gitlab::GroupHierarchy. + new(self.class.where(id: parent_id)). + base_and_ancestors end - # Scopes the model on direct and indirect children of the record + # Returns all the descendants of the current namespace. def descendants - self.class.joins(:route).merge(Route.inside_path(route.path)).reorder('routes.path ASC') + Gitlab::GroupHierarchy. + new(self.class.where(parent_id: id)). + base_and_descendants end def user_ids_for_project_authorizations |