[#7873] Pre-cache git branches/tags after repo_refresh
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 74e79ba..1ca82e8 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -132,6 +132,10 @@
if repo.cached_tags:
repo.cached_tags = []
session(repo).flush()
+ # The first view can be expensive to cache,
+ # so we want to do it here instead of on the first view.
+ repo.get_branches()
+ repo.get_tags()
if not all_commits and not new_clone:
for commit in commit_ids:
diff --git a/Allura/development.ini b/Allura/development.ini
index 395b9a8..bb2ccab 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -298,7 +298,7 @@
scm.import.retry_sleep_secs = 5
; When getting a list of valid references (branches/tags) from a repo, you can cache
-; the resaults in mongo based on a threshold. Set `repo_refs_cache_threshold` (in seconds) and the resulting
+; the results in mongo based on a threshold. Set `repo_refs_cache_threshold` (in seconds) and the resulting
; lists will be cached and served from cache on subsequent requests until reset by `repo_refresh`.
; Set to 0 to cache all references. Remove entirely to cache nothing.
repo_refs_cache_threshold = .5
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index d9ede88..7d87a09 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -545,10 +545,9 @@
if cache:
return cache
- ref_list = getattr(self._git, field_name)
-
refs = []
start_time = time()
+ ref_list = getattr(self._git, field_name)
for ref in ref_list:
try:
hex_sha = ref.commit.hexsha
@@ -587,10 +586,9 @@
return None # no valid heads
return self._git.head.commit.hexsha
- @property
+ @LazyProperty
def heads(self):
- """ In git, heads are just branches """
- return self.branches
+ return self._get_refs('heads')
@LazyProperty
def branches(self):
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 29c6453..917f765 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -390,10 +390,7 @@
def test_default_branch(self):
assert_equal(c.app.default_branch_name, 'master')
- vv = c.app.repo.set_default_branch('zz')
- print('-' * 10)
- print(vv)
- print('-' * 10)
+ c.app.repo.set_default_branch('zz')
assert_equal(c.app.default_branch_name, 'zz')
c.app.repo.set_default_branch('master')
assert_equal(c.app.default_branch_name, 'master')
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 47dc34d..c28daf1 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -746,6 +746,7 @@
repo_dir = pkg_resources.resource_filename(
'forgegit', 'tests/data/testgit.git')
repo = mock.Mock(full_fs_path=repo_dir)
+ repo.cached_branches = []
impl = GM.git_repo.GitImplementation(repo)
self.assertEqual(impl.branches, [
Object(name='master',
@@ -758,6 +759,7 @@
repo_dir = pkg_resources.resource_filename(
'forgegit', 'tests/data/testgit.git')
repo = mock.Mock(full_fs_path=repo_dir)
+ repo.cached_tags = []
impl = GM.git_repo.GitImplementation(repo)
self.assertEqual(impl.tags, [
Object(name='foo',