From 24790ecc23ab4bbc230fe1c03e4439533d34fda3 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 23 Jun 2016 13:47:34 -0700 Subject: [PATCH] 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 --- gertty/db.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gertty/db.py b/gertty/db.py index 7f48736..17b58cf 100644 --- a/gertty/db.py +++ b/gertty/db.py @@ -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: