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/06 16:42:52 UTC

[27/50] git commit: [#4691] Added optimization to computing LCDs

[#4691] Added optimization to computing LCDs

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

Branch: refs/heads/cj/4691
Commit: f916a2bbd63d489f6749d24a57e22f0edac34577
Parents: 9624d79
Author: Cory Johns <jo...@geek.net>
Authored: Thu Jan 10 23:50:59 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Feb 5 20:22:51 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo.py |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f916a2bb/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 1c9ff1b..881730f 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -711,6 +711,7 @@ class LastCommit(RepoObject):
         if lcd is None and create:
             commit = cache.get(Commit, {'_id': last_commit_id})
             lcd = cls._build(commit.get_path(path))
+            cache.set(cls, {'path': path, 'commit_id': last_commit_id}, lcd)
         return lcd
 
     @classmethod
@@ -722,12 +723,28 @@ class LastCommit(RepoObject):
         path = tree.path().strip('/')
         entries = []
         tree_nodes = set([n.name for n in tree.tree_ids])
+        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
         for node in chain(tree.tree_ids, tree.blob_ids, tree.other_ids):
-            commit_id = tree.repo.commits(os.path.join(path, node.name), tree.commit._id, limit=1)
+            not_changed = os.path.join(path, node.name) not in tree.commit.changed_paths
+            if not_changed and prev_lcd:
+                commit_id = prev_lcd.entry_by_name(node.name).commit_id
+            else:
+                commit_id = tree.repo.commits(os.path.join(path, node.name), tree.commit._id, limit=1)
+                if commit_id:
+                    commit_id = commit_id[0]
+                else:
+                    log.error('Tree node not recognized by SCM: %s @ %s', os.path.join(path, node.name), tree.commit._id)
+                    commit_id = tree.commit._id
             entries.append(dict(
                     name=node.name,
                     type='DIR' if node.name in tree_nodes else 'BLOB',
-                    commit_id=commit_id[0],
+                    commit_id=commit_id,
                 ))
         lcd = cls(
                 commit_id=tree.commit._id,
@@ -736,6 +753,11 @@ class LastCommit(RepoObject):
             )
         return lcd
 
+    def entry_by_name(self, name):
+        for node in self.entries:
+            if node.name == name:
+                return node
+
 mapper(Commit, CommitDoc, repository_orm_session)
 mapper(Tree, TreeDoc, repository_orm_session)
 mapper(LastCommit, LastCommitDoc, repository_orm_session)