You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/02/25 20:48:41 UTC
git commit: [#5788] Added some small performance tweaks for LCD
creation
Updated Branches:
refs/heads/cj/5788 [created] cbb165b10
[#5788] Added some small performance tweaks for LCD creation
Signed-off-by: Cory Johns <jo...@geek.net>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/cbb165b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/cbb165b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/cbb165b1
Branch: refs/heads/cj/5788
Commit: cbb165b10a4ecc1540371f4de306c7ae196a9fc5
Parents: c3f622e
Author: Cory Johns <jo...@geek.net>
Authored: Fri Feb 22 21:09:58 2013 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Mon Feb 25 15:20:29 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/repo.py | 17 +++++++++++------
Allura/allura/model/repo_refresh.py | 6 ++++--
2 files changed, 15 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cbb165b1/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index e44c483..55413dc 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -745,6 +745,13 @@ class LastCommit(RepoObject):
return commit_id
@classmethod
+ def _prev_commit_id(cls, commit, path):
+ commit_id = list(commit.repo.commits(path, commit._id, skip=1, limit=1))
+ if not commit_id:
+ return None
+ return commit_id[0]
+
+ @classmethod
def get(cls, tree, create=True):
'''Find or build the LastCommitDoc for the given tree.'''
cache = getattr(c, 'model_cache', '') or ModelCache()
@@ -767,12 +774,10 @@ class LastCommit(RepoObject):
path = tree.path().strip('/')
entries = []
prev_lcd = None
- parent = tree.commit.get_parent()
- if parent:
- try:
- prev_lcd = cls.get(parent.get_path(path), create=False)
- except KeyError as e:
- prev_lcd = None # will fail if path was added this commit
+ prev_lcd_cid = cls._prev_commit_id(tree.commit, path)
+ if prev_lcd_cid:
+ cache = getattr(c, 'model_cache', '') or ModelCache()
+ prev_lcd = cache.get(cls, {'path': path, 'commit_id': prev_lcd_cid})
entries = {}
nodes = set([node.name for node in chain(tree.tree_ids, tree.blob_ids, tree.other_ids)])
changed = set([node for node in nodes if os.path.join(path, node) in tree.commit.changed_paths])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cbb165b1/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index adb2b33..c50cffc 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -499,9 +499,11 @@ def compute_lcds(commit, cache):
_compute_lcds(tree, cache)
def _compute_lcds(tree, cache):
- if tree.path().strip('/') not in tree.commit.changed_paths:
+ path = tree.path().strip('/')
+ if path not in tree.commit.changed_paths:
return
- lcd = LastCommit.get(tree, create=True) # auto-vivify LCD
+ if not cache.get(LastCommit, dict(commit_id=tree.commit._id, path=path)):
+ lcd = LastCommit._build(tree)
for x in tree.tree_ids:
sub_tree = _pull_tree(cache, x.id, tree, x.name)
_compute_lcds(sub_tree, cache)