summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-03-11 16:45:27 +0000
committerErik Johnston <erik@matrix.org>2016-03-11 16:45:27 +0000
commit15122da0e275ba18ec4633129715067a637f38af (patch)
treeed99c39adf7b173fef7ae27a2ebc1e0d9665e6ed /synapse/storage
parentEmtpy commit (diff)
downloadsynapse-15122da0e275ba18ec4633129715067a637f38af.tar.xz
Thats not how transactions work.
Diffstat (limited to '')
-rw-r--r--synapse/storage/registration.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py
index 18898c44eb..bd4eb88a92 100644
--- a/synapse/storage/registration.py
+++ b/synapse/storage/registration.py
@@ -197,26 +197,29 @@ class RegistrationStore(SQLBaseStore):
     @defer.inlineCallbacks
     def user_delete_access_tokens(self, user_id, except_token_ids=[]):
         def f(txn):
-            txn.execute(
-                "SELECT token FROM access_tokens"
-                " WHERE user_id = ? AND id NOT IN (%s)" % (
+            sql = "SELECT token FROM access_tokens WHERE user_id = ?"
+            clauses = [user_id]
+
+            if except_token_ids:
+                sql += " AND id NOT IN (%s)" % (
                     ",".join(["?" for _ in except_token_ids]),
-                ),
-                [user_id] + except_token_ids
-            )
+                )
+                clauses += except_token_ids
+
+            txn.execute(sql, clauses)
 
-            while True:
-                rows = txn.fetchmany(100)
-                if not rows:
-                    break
+            rows = txn.fetchall()
 
-                for row in rows:
+            n = 100
+            chunks = [rows[i:i + n] for i in xrange(0, len(rows), n)]
+            for chunk in chunks:
+                for row in chunk:
                     txn.call_after(self.get_user_by_access_token.invalidate, (row[0],))
 
                 txn.execute(
                     "DELETE FROM access_tokens WHERE token in (%s)" % (
-                        ",".join(["?" for _ in rows]),
-                    ), [r[0] for r in rows]
+                        ",".join(["?" for _ in chunk]),
+                    ), [r[0] for r in chunk]
                 )
 
         yield self.runInteraction("user_delete_access_tokens", f)