Fixup removal of duplicate user_ips rows (#4432)

* Remove unnecessary ORDER BY clause

* Add logging

* Newsfile
This commit is contained in:
Erik Johnston 2019-01-23 08:45:18 +00:00 committed by Amber Brown
parent 6129e52f43
commit 90743c9d89
2 changed files with 6 additions and 1 deletions

1
changelog.d/4432.misc Normal file
View File

@ -0,0 +1 @@
Apply a unique index to the user_ips table, preventing duplicates.

View File

@ -143,6 +143,11 @@ class ClientIpStore(background_updates.BackgroundUpdateStore):
# If it returns None, then we're processing the last batch # If it returns None, then we're processing the last batch
last = end_last_seen is None 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): def remove(txn):
# This works by looking at all entries in the given time span, and # 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 # then for each (user_id, access_token, ip) tuple in that range
@ -170,7 +175,6 @@ class ClientIpStore(background_updates.BackgroundUpdateStore):
SELECT user_id, access_token, ip SELECT user_id, access_token, ip
FROM user_ips FROM user_ips
WHERE {} WHERE {}
ORDER BY last_seen
) c ) c
INNER JOIN user_ips USING (user_id, access_token, ip) INNER JOIN user_ips USING (user_id, access_token, ip)
GROUP BY user_id, access_token, ip GROUP BY user_id, access_token, ip