summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Hegyi <ahegyi@gitlab.com>2019-07-02 08:19:46 +0000
committerThong Kuah <tkuah@gitlab.com>2019-07-02 08:19:46 +0000
commitb8563dadc02ecd390c550ba9a76180f65c53c3af (patch)
tree80f561bb14310805f7d2e56424723c2cbd3bd108
parentebf289fded498bf928ae979245f4be753865781a (diff)
downloadgitlab-ce-b8563dadc02ecd390c550ba9a76180f65c53c3af.tar.gz
Memoizing root_ancestor in Namespace
The root_ancestor method is heavily used in EE for the group_saml feature. Having this memoization implemented in CE would eliminate the need of overriding the root_ancestor method in EE.
-rw-r--r--app/models/namespace.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index f9b53b2b70a..bfa33dc86ac 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -250,7 +250,9 @@ class Namespace < ApplicationRecord
end
def root_ancestor
- self_and_ancestors.reorder(nil).find_by(parent_id: nil)
+ strong_memoize(:root_ancestor) do
+ self_and_ancestors.reorder(nil).find_by(parent_id: nil)
+ end
end
def subgroup?