From b8563dadc02ecd390c550ba9a76180f65c53c3af Mon Sep 17 00:00:00 2001 From: Adam Hegyi Date: Tue, 2 Jul 2019 08:19:46 +0000 Subject: [PATCH] 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. --- app/models/namespace.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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?