Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-04-24 19:01:37 +0300
committerSean McGivern <sean@mcgivern.me.uk>2017-04-24 19:01:37 +0300
commit9d17ad1048779c3e8ff5f8af4d6497a1140cfe33 (patch)
treee1be814be515e32c561f193f6547768e1a8c7b26 /app
parent53301454163bba1b887bbbdba9f91420e951bda1 (diff)
parenta0edaa9210642f23ef3ea4984c6d6f77cbbba878 (diff)
Merge branch 'sh-optimize-duplicate-routable-full-path' into 'master'
Cache Routable#full_path in RequestStore to reduce duplicate route loads See merge request !10872
Diffstat (limited to 'app')
-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