Commit 63da396f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'performance-tune' into 'master'

Performance improvements

* Cache project branches and tags into variables
* Cache lookup results into hash to prevent repeating same requests to git repo
* Cache head commit and head tree

See merge request !417
parents 3b5df555 d96098e9
...@@ -17,6 +17,7 @@ v 7.10.0 (unreleased) ...@@ -17,6 +17,7 @@ v 7.10.0 (unreleased)
- Passing the name of pushed ref to CI service (requires GitLab CI 7.9+) - Passing the name of pushed ref to CI service (requires GitLab CI 7.9+)
- Add location field to user profile - Add location field to user profile
- Fix print view for markdown files and wiki pages - Fix print view for markdown files and wiki pages
- Improve GitLab performance when working with git repositories
v 7.9.0 (unreleased) v 7.9.0 (unreleased)
- Add HipChat integration documentation (Stan Hu) - Add HipChat integration documentation (Stan Hu)
......
...@@ -62,24 +62,28 @@ class Repository ...@@ -62,24 +62,28 @@ class Repository
def add_branch(branch_name, ref) def add_branch(branch_name, ref)
cache.expire(:branch_names) cache.expire(:branch_names)
@branches = nil
gitlab_shell.add_branch(path_with_namespace, branch_name, ref) gitlab_shell.add_branch(path_with_namespace, branch_name, ref)
end end
def add_tag(tag_name, ref, message = nil) def add_tag(tag_name, ref, message = nil)
cache.expire(:tag_names) cache.expire(:tag_names)
@tags = nil
gitlab_shell.add_tag(path_with_namespace, tag_name, ref, message) gitlab_shell.add_tag(path_with_namespace, tag_name, ref, message)
end end
def rm_branch(branch_name) def rm_branch(branch_name)
cache.expire(:branch_names) cache.expire(:branch_names)
@branches = nil
gitlab_shell.rm_branch(path_with_namespace, branch_name) gitlab_shell.rm_branch(path_with_namespace, branch_name)
end end
def rm_tag(tag_name) def rm_tag(tag_name)
cache.expire(:tag_names) cache.expire(:tag_names)
@tags = nil
gitlab_shell.rm_tag(path_with_namespace, tag_name) gitlab_shell.rm_tag(path_with_namespace, tag_name)
end end
...@@ -180,8 +184,17 @@ class Repository ...@@ -180,8 +184,17 @@ class Repository
end end
end end
def lookup_cache
@lookup_cache ||= {}
end
def method_missing(m, *args, &block) def method_missing(m, *args, &block)
raw_repository.send(m, *args, &block) if m == :lookup && !block_given?
lookup_cache[m] ||= {}
lookup_cache[m][args.join(":")] ||= raw_repository.send(m, *args, &block)
else
raw_repository.send(m, *args, &block)
end
end end
def respond_to?(method) def respond_to?(method)
...@@ -235,12 +248,20 @@ class Repository ...@@ -235,12 +248,20 @@ class Repository
end end
def head_commit def head_commit
commit(self.root_ref) @head_commit ||= commit(self.root_ref)
end
def head_tree
@head_tree ||= Tree.new(self, head_commit.sha, nil)
end end
def tree(sha = :head, path = nil) def tree(sha = :head, path = nil)
if sha == :head if sha == :head
sha = head_commit.sha if path.nil?
return head_tree
else
sha = head_commit.sha
end
end end
Tree.new(self, sha, path) Tree.new(self, sha, path)
...@@ -368,6 +389,18 @@ class Repository ...@@ -368,6 +389,18 @@ class Repository
end end
end end
def branches
@branches ||= raw_repository.branches
end
def tags
@tags ||= raw_repository.tags
end
def root_ref
@root_ref ||= raw_repository.root_ref
end
private private
def cache def cache
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment