Thats not how transactions work.

This commit is contained in:
Erik Johnston 2016-03-11 16:45:27 +00:00
parent ae6ff09494
commit 15122da0e2
1 changed files with 16 additions and 13 deletions

View File

@ -197,26 +197,29 @@ class RegistrationStore(SQLBaseStore):
@defer.inlineCallbacks @defer.inlineCallbacks
def user_delete_access_tokens(self, user_id, except_token_ids=[]): def user_delete_access_tokens(self, user_id, except_token_ids=[]):
def f(txn): def f(txn):
txn.execute( sql = "SELECT token FROM access_tokens WHERE user_id = ?"
"SELECT token FROM access_tokens" clauses = [user_id]
" WHERE user_id = ? AND id NOT IN (%s)" % (
if except_token_ids:
sql += " AND id NOT IN (%s)" % (
",".join(["?" for _ in except_token_ids]), ",".join(["?" for _ in except_token_ids]),
),
[user_id] + except_token_ids
) )
clauses += except_token_ids
while True: txn.execute(sql, clauses)
rows = txn.fetchmany(100)
if not rows:
break
for row in rows: rows = txn.fetchall()
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.call_after(self.get_user_by_access_token.invalidate, (row[0],))
txn.execute( txn.execute(
"DELETE FROM access_tokens WHERE token in (%s)" % ( "DELETE FROM access_tokens WHERE token in (%s)" % (
",".join(["?" for _ in rows]), ",".join(["?" for _ in chunk]),
), [r[0] for r in rows] ), [r[0] for r in chunk]
) )
yield self.runInteraction("user_delete_access_tokens", f) yield self.runInteraction("user_delete_access_tokens", f)