Rev 415: Find the right compromise. in http://bazaar.launchpad.net/~jameinel/loggerhead/history_db
John Arbash Meinel
john at arbash-meinel.com
Wed Apr 14 20:43:49 BST 2010
At http://bazaar.launchpad.net/~jameinel/loggerhead/history_db
------------------------------------------------------------
revno: 415
revision-id: john at arbash-meinel.com-20100414194330-hlil7qe0opsow8r2
parent: john at arbash-meinel.com-20100414185054-5q694mcl22u4v718
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: history_db
timestamp: Wed 2010-04-14 14:43:30 -0500
message:
Find the right compromise.
Navigation just needs to be able to find the next and previous pages.
So we just walk until we hit the stop rev, and continue on for 1 page.
For emacs, that means we can load the changes page in about 400ms.
Walking a really old page starting at the current tip would be slow,
but nothing like this.
-------------- next part --------------
=== modified file 'loggerhead/controllers/changelog_ui.py'
--- a/loggerhead/controllers/changelog_ui.py 2010-04-14 18:50:54 +0000
+++ b/loggerhead/controllers/changelog_ui.py 2010-04-14 19:43:30 +0000
@@ -50,7 +50,8 @@
try:
revid, start_revid, revid_list = history.get_view(
- revid, start_revid, filter_file_id, query)
+ revid, start_revid, filter_file_id, query,
+ extra_rev_count=pagesize+1)
util.set_context(kwargs)
if (query is not None) and (len(revid_list) == 0):
=== modified file 'loggerhead/history.py'
--- a/loggerhead/history.py 2010-04-14 18:50:54 +0000
+++ b/loggerhead/history.py 2010-04-14 19:43:30 +0000
@@ -342,17 +342,10 @@
if revid_list is None:
# I assume this just returns the mainline, as such, just walk the
# mainline and be done.
- # TODO: I think we could just call
- # self._branch.repository.iter_reverse_revision_history(start_revid)
- # or something like that.
- # TODO: This operation appears at the top of profiling currently
- # when loading the 'changes' page. Especially unfortunate
- # given that we only show ~20 revs...
- if start_revid == self.last_revid:
- history = reversed(self._branch.revision_history())
- else:
- history = self._branch.repository.iter_reverse_revision_history(
- start_revid)
+ # Note: Don't use self._branch.revision_history, as that always
+ # grabs the full history, and we now support stopping early.
+ history = self._branch.repository.iter_reverse_revision_history(
+ start_revid)
for rev_id in history:
yield rev_id
return
@@ -514,12 +507,38 @@
if file_id is not None:
revlist = list(
self.get_short_revision_history_by_fileid(file_id, revid))
- revlist = list(self.get_revids_from(revlist, revid))
+ revlist = self.get_revids_from(revlist, revid)
else:
- revlist = list(self.get_revids_from(None, revid))
+ revlist = self.get_revids_from(None, revid)
return revlist
- def get_view(self, revid, start_revid, file_id, query=None):
+ def _iterate_sufficiently(self, iterable, stop_at, extra_rev_count):
+ """Return a list of iterable.
+
+ If extra_rev_count is None, fully consume iterable.
+ Otherwise, stop at 'stop_at' + extra_rev_count.
+
+ Example:
+ iterate until you find stop_at, then iterate 10 more times.
+ """
+ if extra_rev_count is None:
+ return list(iterable)
+ result = []
+ found = False
+ for n in iterable:
+ result.append(n)
+ if n == stop_at:
+ found = True
+ break
+ if found:
+ for count, n in enumerate(iterable):
+ result.append(n)
+ if count >= extra_rev_count:
+ break
+ return result
+
+ def get_view(self, revid, start_revid, file_id, query=None,
+ extra_rev_count=None):
"""
use the URL parameters (revid, start_revid, file_id, and query) to
determine the revision list we're viewing (start_revid, file_id, query)
@@ -529,7 +548,11 @@
- if a file_id is given, we're viewing revisions for a specific
file.
- if a start_revid is given, we're viewing the branch from a
- specific revision up the tree.
+ specific revision up the mainline.
+ - if extra_rev_count is given, find the view from start_revid =>
+ revid, and continue an additional 'extra_rev_count'. If not
+ given, then revid_list will contain the full history of
+ start_revid
these may be combined to view revisions for a specific file, from
a specific revision, with a specific search query.
@@ -548,12 +571,16 @@
if query is None:
revid_list = self.get_file_view(start_revid, file_id)
+ revid_list = self._iterate_sufficiently(revid_list, revid,
+ extra_rev_count)
if revid is None:
revid = start_revid
if revid not in revid_list:
# if the given revid is not in the revlist, use a revlist that
# starts at the given revid.
revid_list = self.get_file_view(revid, file_id)
+ revid_list = self._iterate_sufficiently(revid_list, revid,
+ extra_rev_count)
start_revid = revid
return revid, start_revid, revid_list
More information about the bazaar-commits
mailing list