Fix "too many SQL variables" error

SQLite has a limit of 999 variable substitutions.  If we have more
changes than that in the database, the getChangeIDs call won't work.

This version of the method was written before change expiration.
Now, changes in the local database are much more likely to be active,
so a query is less likely to return useless data.  However, in a
busy system, we are likely to see more than 999 local changes.

One way to correct this involves chunking the query, but then we will
essentially be asking SQLite to run a full table scan for each chunk.
Instead, let's ask it to do a single full table scan, return all of
the change ids, and have python filter them.

Change-Id: Ia5a6675522846a16526b11cc2d62d16f21bf59b7
Co-Authored-By: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
James E. Blair 2016-06-23 13:47:34 -07:00
parent 76c8344c8d
commit 24790ecc23
1 changed files with 3 additions and 2 deletions

View File

@ -832,8 +832,9 @@ class DatabaseSession(object):
# the set of supplied IDs. This is used when sync'ing the changesets
# locally with the remote changes.
if not ids:
return set([])
return set([r[0] for r in self.session().query(Change.id).filter(Change.id.in_(ids)).all()])
return set()
query = self.session().query(Change.id)
return set(ids).intersection(r[0] for r in query.all())
def getChangesByChangeID(self, change_id):
try: