summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-03-10 15:38:00 +0000
committerErik Johnston <erik@matrix.org>2016-03-10 15:38:00 +0000
commit703826886ca04154b70cf9e082916001275733f9 (patch)
treed8e8449861fbc9c5611e023bb7894621e7addff0
parentMerge pull request #637 from blide/develop (diff)
parentUpdate users table in a batched manner (diff)
downloadsynapse-703826886ca04154b70cf9e082916001275733f9.tar.xz
Merge pull request #639 from matrix-org/erikj/as_user_update_batch
Update users table in a batched manner
-rw-r--r--synapse/storage/schema/delta/30/as_users.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/synapse/storage/schema/delta/30/as_users.py b/synapse/storage/schema/delta/30/as_users.py
index 4da3c59de2..4f6e9dd540 100644
--- a/synapse/storage/schema/delta/30/as_users.py
+++ b/synapse/storage/schema/delta/30/as_users.py
@@ -52,12 +52,17 @@ def run_upgrade(cur, database_engine, config, *args, **kwargs):
                         " service (IDs %s and %s); assigning arbitrarily to %s" %
                         (user_id, owned[user_id], appservice.id, owned[user_id])
                     )
-                owned[user_id] = appservice.id
-
-    for user_id, as_id in owned.items():
-        cur.execute(
-            database_engine.convert_param_style(
-                "UPDATE users SET appservice_id = ? WHERE name = ?"
-            ),
-            (as_id, user_id)
-        )
+                owned.setdefault(appservice.id, []).append(user_id)
+
+    for as_id, user_ids in owned.items():
+        n = 100
+        user_chunks = (user_ids[i:i + 100] for i in xrange(0, len(user_ids), n))
+        for chunk in user_chunks:
+            cur.execute(
+                database_engine.convert_param_style(
+                    "UPDATE users SET appservice_id = ? WHERE name IN (%s)" % (
+                        ",".join("?" for _ in chunk),
+                    )
+                ),
+                [as_id] + chunk
+            )