summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-11-26 15:50:17 +0000
committerErik Johnston <erik@matrix.org>2019-11-26 15:54:48 +0000
commit8bb7b15894462c6a0ba81f7198f23a140100331d (patch)
tree5fa7c203e2955e908c9a3b3327d151f63ee45ed9
parentMerge branch 'master' into develop (diff)
downloadsynapse-8bb7b15894462c6a0ba81f7198f23a140100331d.tar.xz
Fix find_next_generated_user_id_localpart
-rw-r--r--synapse/storage/data_stores/main/registration.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/synapse/storage/data_stores/main/registration.py b/synapse/storage/data_stores/main/registration.py
index 6a594c160c..c124bbb88b 100644
--- a/synapse/storage/data_stores/main/registration.py
+++ b/synapse/storage/data_stores/main/registration.py
@@ -19,7 +19,6 @@ import logging
 import re
 
 from six import iterkeys
-from six.moves import range
 
 from twisted.internet import defer
 from twisted.internet.defer import Deferred
@@ -482,12 +481,8 @@ class RegistrationWorkerStore(SQLBaseStore):
         """
         Gets the localpart of the next generated user ID.
 
-        Generated user IDs are integers, and we aim for them to be as small as
-        we can. Unfortunately, it's possible some of them are already taken by
-        existing users, and there may be gaps in the already taken range. This
-        function returns the start of the first allocatable gap. This is to
-        avoid the case of ID 1000 being pre-allocated and starting at 1001 while
-        0-999 are available.
+        Generated user IDs are integers, so we find the largest integer user ID
+        already taken and return that plus one.
         """
 
         def _find_next_generated_user_id(txn):
@@ -503,9 +498,11 @@ class RegistrationWorkerStore(SQLBaseStore):
                 match = regex.search(user_id)
                 if match:
                     found.add(int(match.group(1)))
-            for i in range(len(found) + 1):
-                if i not in found:
-                    return i
+
+            if not found:
+                return 1
+
+            return max(found) + 1
 
         return (
             (