Support paging in queries

When querying for a list of changes to sync, use the sortkey to
handle multiple pages of query results.  By default, Gerrit only
returns 500 results.

Change-Id: I12049b4dcfa796650099b9ba71377a5bcf3feae0
This commit is contained in:
James E. Blair 2014-08-30 15:57:30 -07:00
parent eb2a491129
commit 97c0d89ea5
1 changed files with 15 additions and 2 deletions

View File

@ -154,8 +154,21 @@ class SyncProjectTask(Task):
if project.updated:
# Allow 4 seconds for request time, etc.
query += ' -age:%ss' % (int(math.ceil((now-project.updated).total_seconds())) + 4,)
changes = sync.get('changes/?q=%s' % query)
self.log.debug('Query: %s ' % (query,))
else:
query += ' status:open'
changes = []
sortkey = ''
while True:
# We don't actually want to limit to 500, but that's the server-side default, and
# if we don't specify this, we won't get a _more_changes flag.
q = 'changes/?n=500%s&q=%s' % (sortkey, query,)
self.log.debug('Query: %s ' % (q,))
batch = sync.get(q)
changes += batch
if batch and '_more_changes' in batch[-1]:
sortkey = '&N=%s' % (batch[-1]['_sortkey'],)
else:
break
with app.db.getSession() as session:
for c in changes:
# For now, just sync open changes or changes already