allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [10/20] git commit: [#5788] Added some small performance tweaks for LCD creation
Date Thu, 28 Feb 2013 22:38:16 GMT
[#5788] Added some small performance tweaks for LCD creation

Signed-off-by: Cory Johns <johnsca@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/3eaf6907
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/3eaf6907
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/3eaf6907

Branch: refs/heads/cj/5788
Commit: 3eaf6907e50868f64075d5800f89036517482af8
Parents: 36b8c92
Author: Cory Johns <johnsca@geek.net>
Authored: Fri Feb 22 21:09:58 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Thu Feb 28 21:48:32 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/3eaf6907/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/3eaf6907/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)


Mime
View raw message