Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fixup removal of duplicate user_ips rows #4432

Merged
merged 3 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/4432.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Apply a unique index to the user_ips table, preventing duplicates.
6 changes: 5 additions & 1 deletion synapse/storage/client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -170,7 +175,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
Expand Down