phabstatus: batch peekahead for smartlog

Summary:
Phabstatus for smartlog uses `PeekeaheadList` rather than `PeekaheadRevsetIterator` as
all of the commits are known ahead of time, and we don't need to collect together
batches as we iterate across the revset.

However, we should still batch up requests to Phabricator, as users with very high
numbers of commits in their smartlog may hit timeouts.

Add a batching mechanism to `PeekaheadList` that splits the list into chunks to
return with each peekahead.

Reviewed By: liubov-dmitrieva

Differential Revision: D23840071

fbshipit-source-id: 68596c7eb4f7404ce6109e69914f328565e34582
This commit is contained in:
Mark Thomas 2020-09-22 07:24:49 -07:00 committed by Facebook GitHub Bot
parent c68e928d6f
commit ee0299cda0

View File

@ -343,20 +343,32 @@ class PeekaheadList(object):
the full list.
"""
def __init__(self, revs):
def __init__(self, revs, chunksize):
self.revs = revs
self.chunksize = chunksize
self.offset = 0
self.done = False
def peekahead(self):
self.done = True
return self.revs
def peekahead(self, chunksize=None):
chunksize = chunksize or self.chunksize
revs = self.revs[self.offset : self.offset + self.chunksize]
self.offset += self.chunksize
if self.offset >= len(self.revs):
self.done = True
return revs
def _getsmartlogdag(orig, ui, repo, revs, *args):
# smartlog just uses a plain list for its revisions, and not an
# abstractsmartset type. We just save a copy of it.
repo._phabstatusrevs = PeekaheadList(revs)
return orig(ui, repo, revs, *args)
# abstractsmartset type. We just save a copy of it in the order
# the commits appear in smartlog.
results, reserved = orig(ui, repo, revs, *args)
revs = [result[0] for result in results]
peekahead = repo.ui.configint("phabstatus", "logpeekaheadlist", 30)
repo._phabstatusrevs = PeekaheadList(revs, peekahead)
return results, reserved
def extsetup(ui):