From 7a1795b29792619638a9e3a1de6d9cebbf4140c7 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Fri, 6 May 2016 10:01:14 -0400 Subject: [PATCH] Support SyncQueriedChanges batching in Gerrit >=2.9 The commits 76ccd91ff92f1e4b29286fdeda4e687937615a81 and 74abd8e31841e30d6a6e243e34f720b07723cc3c added support in (what was then) the SyncProjectTask for the changes in the Gerrit API to batching of queries starting with Gerrit 2.9. This patch applies the same fixes to the SyncQueriedChangesTask. Change-Id: Ic2786c10ac326d453b5b7a8bfcad3d1e87db1f52 --- gertty/sync.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gertty/sync.py b/gertty/sync.py index 5f8539f..11cee08 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -419,6 +419,7 @@ class SyncQueriedChangesTask(Task): changes = [] sortkey = '' done = False + offset = 0 while not done: # 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. @@ -429,8 +430,12 @@ class SyncQueriedChangesTask(Task): if batch: changes += batch if '_more_changes' in batch[-1]: - sortkey = '&N=%s' % (batch[-1]['_sortkey'],) done = False + if '_sortkey' in batch[-1]: + sortkey = '&N=%s' % (batch[-1]['_sortkey'],) + else: + offset += len(batch) + sortkey = '&start=%s' % (offset,) change_ids = [c['id'] for c in changes] with app.db.getSession() as session: # Winnow the list of IDs to only the ones in the local DB.