You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/02/05 21:23:34 UTC
[32/42] git commit: [#4691] Convert GitImplementation.commits to use
mongo instead of calling git, for performance
[#4691] Convert GitImplementation.commits to use mongo instead of calling git, for performance
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/888e2739
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/888e2739
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/888e2739
Branch: refs/heads/master
Commit: 888e27392aaff4b37aa85b16620bc9d34d7590f4
Parents: f916a2b
Author: Cory Johns <jo...@geek.net>
Authored: Fri Jan 11 22:53:55 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Feb 5 20:22:52 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/repo.py | 22 +++++++++++-----
ForgeGit/forgegit/model/git_repo.py | 38 ++++++++++++++++++++++--------
2 files changed, 43 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/888e2739/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 881730f..c0c1b27 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -702,14 +702,27 @@ class LastCommit(RepoObject):
return '<LastCommit /%s %s>' % (self.path, self.commit_id)
@classmethod
+ def _last_commit_id(cls, commit, path):
+ if not commit.repo:
+ import ipdb; ipdb.set_trace()
+ commit_id = list(commit.repo.commits(path, commit._id, limit=1))
+ if commit_id:
+ commit_id = commit_id[0]
+ else:
+ log.error('Tree node not recognized by SCM: %s @ %s', path, commit._id)
+ commit_id = commit._id
+ return commit_id
+
+ @classmethod
def get(cls, tree, create=True):
'''Find or build the LastCommitDoc for the given tree.'''
cache = getattr(c, 'model_cache', '') or ModelCache()
path = tree.path().strip('/')
- last_commit_id = tree.repo.commits(path, tree.commit._id, limit=1)[0]
+ last_commit_id = cls._last_commit_id(tree.commit, path)
lcd = cache.get(cls, {'path': path, 'commit_id': last_commit_id})
if lcd is None and create:
commit = cache.get(Commit, {'_id': last_commit_id})
+ commit.set_context(tree.repo)
lcd = cls._build(commit.get_path(path))
cache.set(cls, {'path': path, 'commit_id': last_commit_id}, lcd)
return lcd
@@ -735,12 +748,7 @@ class LastCommit(RepoObject):
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
+ commit_id = cls._last_commit_id(tree.commit, os.path.join(path, node.name))
entries.append(dict(
name=node.name,
type='DIR' if node.name in tree_nodes else 'BLOB',
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/888e2739/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index cb1e685..d7409d5 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -11,6 +11,7 @@ import tg
import git
import gitdb
from pylons import app_globals as g
+from pylons import c
from pymongo.errors import DuplicateKeyError
from ming.base import Object
@@ -120,12 +121,13 @@ class GitImplementation(M.RepositoryImplementation):
if ref.name == rev:
rev = ref.object_id
break
- result = M.repo.Commit.query.get(_id=rev)
+ cache = getattr(c, 'model_cache', '') or M.repo.ModelCache()
+ result = cache.get(M.repo.Commit, dict(_id=rev))
if result is None:
# find the id by branch/tag name
try:
impl = self._git.rev_parse(str(rev) + '^0')
- result = M.repo.Commit.query.get(_id=impl.hexsha)
+ result = cache.get(M.repo.Commit, dict(_id=impl.hexsha))
except Exception:
url = ''
try:
@@ -235,14 +237,30 @@ class GitImplementation(M.RepositoryImplementation):
return doc
def commits(self, path=None, rev=None, skip=None, limit=None):
- params = dict(paths=path)
- if rev is not None:
- params['rev'] = rev
- if skip is not None:
- params['skip'] = skip
- if limit is not None:
- params['max_count'] = limit
- return [c.hexsha for c in self._git.iter_commits(**params)]
+ #params = dict(paths=path)
+ #if rev is not None:
+ # params['rev'] = rev
+ #if skip is not None:
+ # params['skip'] = skip
+ #if limit is not None:
+ # params['max_count'] = limit
+ #return [c.hexsha for c in self._git.iter_commits(**params)]
+ if rev is None:
+ rev = 'HEAD'
+ if skip is None:
+ skip = 0
+ max = skip + limit if limit is not None else None
+ commit = self.commit(rev)
+ i = 0
+ while commit:
+ if path is None or path in commit.changed_paths:
+ if i >= skip:
+ yield commit._id
+ i += 1
+ if max is not None and i > max:
+ break
+ commit = commit.get_parent()
+
def commits_count(self, path=None, rev=None):
commit = self._git.commit(rev)