summaryrefslogtreecommitdiff
path: root/app/models/namespace.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-11-30 14:26:08 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2017-12-04 17:43:48 +0100
commit20f78421c82d626a3b43924146b7878fe4777ae8 (patch)
treeb24c602574cb20c907a1ac228c8b00c104cbc836 /app/models/namespace.rb
parent07aaa59b1c28bc7be9fdd98c9334522f60306723 (diff)
downloadgitlab-ce-20f78421c82d626a3b43924146b7878fe4777ae8.tar.gz
Cache the forks in a namespace in the RequestStore
On the `show` of a project that is part of a fork network. We check if the user already created a fork of this project in their personal namespace. We do this in several places, so caching the result of this query in the request store prevents us from repeating it.
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r--app/models/namespace.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index fa76729a702..901dbf2ba69 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -139,7 +139,17 @@ class Namespace < ActiveRecord::Base
def find_fork_of(project)
return nil unless project.fork_network
- project.fork_network.find_forks_in(projects).first
+ if RequestStore.active?
+ forks_in_namespace = RequestStore.fetch("namespaces:#{id}:forked_projects") do
+ Hash.new do |found_forks, project|
+ found_forks[project] = project.fork_network.find_forks_in(projects).first
+ end
+ end
+
+ forks_in_namespace[project]
+ else
+ project.fork_network.find_forks_in(projects).first
+ end
end
def lfs_enabled?