summaryrefslogtreecommitdiff
path: root/app/models/concerns/routable.rb
diff options
context:
space:
mode:
authorRuben Davila <rdavila84@gmail.com>2017-05-02 13:20:41 -0500
committerRuben Davila <rdavila84@gmail.com>2017-05-02 13:20:41 -0500
commitbbfbcebdf69261bac6aa142f430719955e8e86b9 (patch)
tree25916a1a761cb6c8fcdac4b20b76017a7f4506d3 /app/models/concerns/routable.rb
parent3b82444eb7791e58e3e0ba2f08b8ccde48e3d4c6 (diff)
parent920d55b9f8afd35e16351fb57d671acf66092e89 (diff)
downloadgitlab-ce-bbfbcebdf69261bac6aa142f430719955e8e86b9.tar.gz
Merge branch 'master' into 28433-internationalise-cycle-analytics-page
Diffstat (limited to 'app/models/concerns/routable.rb')
-rw-r--r--app/models/concerns/routable.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb
index aca99feee53..b28e05d0c28 100644
--- a/app/models/concerns/routable.rb
+++ b/app/models/concerns/routable.rb
@@ -163,7 +163,20 @@ module Routable
end
end
+ # Every time `project.namespace.becomes(Namespace)` is called for polymorphic_path,
+ # a new instance is instantiated, and we end up duplicating the same query to retrieve
+ # the route. Caching this per request ensures that even if we have multiple instances,
+ # we will not have to duplicate work, avoiding N+1 queries in some cases.
def full_path
+ return uncached_full_path unless RequestStore.active?
+
+ key = "routable/full_path/#{self.class.name}/#{self.id}"
+ RequestStore[key] ||= uncached_full_path
+ end
+
+ private
+
+ def uncached_full_path
if route && route.path.present?
@full_path ||= route.path
else
@@ -173,8 +186,6 @@ module Routable
end
end
- private
-
def full_name_changed?
name_changed? || parent_changed?
end