From 41110ace31402864482ad836f3191fc90561ec47 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 22 Jan 2019 11:48:28 +0000 Subject: [PATCH 1/3] Remove unnecessary ORDER BY clause --- synapse/storage/client_ips.py | 1 - 1 file changed, 1 deletion(-) diff --git a/synapse/storage/client_ips.py b/synapse/storage/client_ips.py index 78721a941a22..80df1990dd10 100644 --- a/synapse/storage/client_ips.py +++ b/synapse/storage/client_ips.py @@ -170,7 +170,6 @@ def remove(txn): SELECT user_id, access_token, ip FROM user_ips WHERE {} - ORDER BY last_seen ) c INNER JOIN user_ips USING (user_id, access_token, ip) GROUP BY user_id, access_token, ip From 3a72fb3e1cace2a9b7f0b3bee6cc2d718a53a640 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 22 Jan 2019 11:59:45 +0000 Subject: [PATCH 2/3] Add logging --- synapse/storage/client_ips.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/synapse/storage/client_ips.py b/synapse/storage/client_ips.py index 80df1990dd10..b228a20ac2a8 100644 --- a/synapse/storage/client_ips.py +++ b/synapse/storage/client_ips.py @@ -143,6 +143,11 @@ def get_last_seen(txn): # If it returns None, then we're processing the last batch last = end_last_seen is None + logger.info( + "Scanning for duplicate 'user_ips' rows in range: %s <= last_seen < %s", + begin_last_seen, end_last_seen, + ) + def remove(txn): # This works by looking at all entries in the given time span, and # then for each (user_id, access_token, ip) tuple in that range From 2f947b7f8e3047bdd7d637716a58022c90d37a13 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 22 Jan 2019 12:04:03 +0000 Subject: [PATCH 3/3] Newsfile --- changelog.d/4432.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4432.misc diff --git a/changelog.d/4432.misc b/changelog.d/4432.misc new file mode 100644 index 000000000000..047061ed3c71 --- /dev/null +++ b/changelog.d/4432.misc @@ -0,0 +1 @@ +Apply a unique index to the user_ips table, preventing duplicates.