[#7873] Add a mongo cache backend to speed up branches/tags
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2d54358b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2d54358b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2d54358b
Branch: refs/heads/master
Commit: 2d54358bcbe608ab453c17a9765909ffdc9c3a36
Parents: 35d5899
Author: Heith Seewald <hseewald@slashdotmedia.com>
Authored: Mon Jun 15 08:24:29 2015 -0400
Committer: Heith Seewald <hseewald@slashdotmedia.com>
Committed: Thu Jun 25 14:10:57 2015 +0000
----------------------------------------------------------------------
ForgeGit/forgegit/git_main.py | 2 +-
ForgeGit/forgegit/model/git_repo.py | 63 ++++++++++++++++++++------------
2 files changed, 40 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2d54358b/ForgeGit/forgegit/git_main.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/git_main.py b/ForgeGit/forgegit/git_main.py
index bb19ec3..62fc0f7 100644
--- a/ForgeGit/forgegit/git_main.py
+++ b/ForgeGit/forgegit/git_main.py
@@ -66,7 +66,7 @@ class ForgeGitApp(RepositoryApp):
def repo(self):
return GM.Repository.query.get(app_config_id=self.config._id)
- @LazyProperty
+ @property
def default_branch_name(self):
return self.repo.get_default_branch('master')
http://git-wip-us.apache.org/repos/asf/allura/blob/2d54358b/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index d6e791c..d9ede88 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -532,31 +532,45 @@ class GitImplementation(M.RepositoryImplementation):
except KeyError:
return False
- @LazyProperty
- def _is_valid(self):
- """ Verifies the validity of the reference objects in the git database
-
- Returns True if no issues are found. This allows us to bypass the individual testing
of each ref
- unless absolutely necessary.
+ def _get_refs(self, field_name):
+ """ Returns a list of valid reference objects (branches or tags) from the git database
- :rtype: bool
+ :return: List of git ref objects.
+ :rtype: list
"""
+
+ cache_name = 'cached_' + field_name
+ cache = getattr(self._repo, cache_name, None)
+
+ if cache:
+ return cache
+
+ ref_list = getattr(self._git, field_name)
+
+ refs = []
+ start_time = time()
+ for ref in ref_list:
+ try:
+ hex_sha = ref.commit.hexsha
+ except ValueError:
+ log.debug(u"Found invalid sha: {}".format(ref))
+ continue
+ refs.append(Object(name=ref.name, object_id=hex_sha))
+ time_taken = time() - start_time
+
+ threshold = tg.config.get('repo_refs_cache_threshold')
try:
- self._git.git.fsck(full=True)
- return True
- except git.GitCommandError as gce:
- log.debug(u"Found inconsistency in {}: {}".format(self._repo.name, gce.stderr))
- return False
+ threshold = float(threshold) if threshold else None
+ except ValueError:
+ threshold = None
+ log.warn('Skipping reference caching - The value for config param '
+ '"repo_refs_cache_threshold" must be a float.')
- def _get_refs(self, ref_list):
- """ Returns a list of valid reference objects from the git database
+ if threshold is not None and time_taken > threshold:
+ setattr(self._repo, cache_name, refs)
+ session(self._repo).flush(self._repo)
- :return: List of git ref objects.
- :rtype: list
- """
- if self._is_valid:
- return [Object(name=ref.name, object_id=ref.commit.hexsha) for ref in ref_list]
- return [Object(name=ref.name, object_id=ref.commit.hexsha) for ref in ref_list if
ref.is_valid()]
+ return refs
@LazyProperty
def head(self):
@@ -573,17 +587,18 @@ class GitImplementation(M.RepositoryImplementation):
return None # no valid heads
return self._git.head.commit.hexsha
- @LazyProperty
+ @property
def heads(self):
- return self._get_refs(self._git.heads)
+ """ In git, heads are just branches """
+ return self.branches
@LazyProperty
def branches(self):
- return self._get_refs(self._git.branches)
+ return self._get_refs('branches')
@LazyProperty
def tags(self):
- return self._get_refs(self._git.tags)
+ return self._get_refs('tags')
def set_default_branch(self, name):
if not name:
|