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: