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/26 19:28:01 UTC

[3/8] git commit: [#5788] Added some small performance tweaks for LCD creation

[#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/d8cd51f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d8cd51f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d8cd51f8

Branch: refs/heads/cj/5788
Commit: d8cd51f83b88506f5898782c65f4309a7a95614b
Parents: c1413ea
Author: Cory Johns <jo...@geek.net>
Authored: Fri Feb 22 21:09:58 2013 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Tue Feb 26 18:27:50 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/d8cd51f8/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 4b922ac..91d4e46 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -748,6 +748,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()
@@ -770,12 +777,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/d8cd51f8/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)