summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-03-11 14:48:20 +0000
committerErik Johnston <erik@matrix.org>2016-03-11 14:48:20 +0000
commitb5afe6bc3853d56c4d7044a293ea1bd2d40d94a7 (patch)
treed86aee969a8881a2319db7168d8978ae4c351aba /synapse/storage
parentMerge pull request #640 from matrix-org/erikj/keyclient_host (diff)
parentmore pep8 (diff)
downloadsynapse-b5afe6bc3853d56c4d7044a293ea1bd2d40d94a7.tar.xz
Merge pull request #641 from matrix-org/dbkr/fix_change_password
Fix logout on password change
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/registration.py39
1 files changed, 18 insertions, 21 deletions
diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py
index aa49f53458..5d45f0c651 100644
--- a/synapse/storage/registration.py
+++ b/synapse/storage/registration.py
@@ -195,27 +195,24 @@ class RegistrationStore(SQLBaseStore):
         })
 
     @defer.inlineCallbacks
-    def user_delete_access_tokens(self, user_id):
-        yield self.runInteraction(
-            "user_delete_access_tokens",
-            self._user_delete_access_tokens, user_id
-        )
-
-    def _user_delete_access_tokens(self, txn, user_id):
-        txn.execute(
-            "DELETE FROM access_tokens WHERE user_id = ?",
-            (user_id, )
-        )
-
-    @defer.inlineCallbacks
-    def flush_user(self, user_id):
-        rows = yield self._execute(
-            'flush_user', None,
-            "SELECT token FROM access_tokens WHERE user_id = ?",
-            user_id
-        )
-        for r in rows:
-            self.get_user_by_access_token.invalidate((r,))
+    def user_delete_access_tokens(self, user_id, except_token_ids):
+        def f(txn):
+            txn.execute(
+                "SELECT id, token FROM access_tokens "
+                "WHERE user_id = ? AND id not in LIMIT 50",
+                (user_id, except_token_ids)
+            )
+            rows = txn.fetchall()
+            for r in rows:
+                txn.call_after(self.get_user_by_access_token.invalidate, (r[1],))
+            txn.execute(
+                "DELETE FROM access_tokens WHERE id in (%s)" % ",".join(
+                    ["?" for _ in rows]
+                ), [r[0] for r in rows]
+            )
+            return len(rows) == 50
+        while (yield self.runInteraction("user_delete_access_tokens", f)):
+            pass
 
     @cached()
     def get_user_by_access_token(self, token):