From 34840cdcef9ecdf721604934b6142040d7561816 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 11 Apr 2017 09:56:54 +0100 Subject: [PATCH 1/3] Fix getting latest device IP for user with no devices --- 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 71e5ea112..5bed255eb 100644 --- a/synapse/storage/client_ips.py +++ b/synapse/storage/client_ips.py @@ -90,6 +90,8 @@ class ClientIpStore(background_updates.BackgroundUpdateStore): are (user_id, device_id) tuples. The values are also dicts, with keys giving the column names """ + if not devices: + defer.returnValue({}) res = yield self.runInteraction( "get_last_client_ip_by_device", @@ -110,6 +112,9 @@ class ClientIpStore(background_updates.BackgroundUpdateStore): @classmethod def _get_last_client_ip_by_device_txn(cls, txn, devices, retcols): + if not devices: + return [] + where_clauses = [] bindings = [] for (user_id, device_id) in devices: From b48045a8f536a503001994066552255c2f6c18ed Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 11 Apr 2017 16:23:24 +0100 Subject: [PATCH 2/3] Don't bother with outer check for now --- synapse/storage/client_ips.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/synapse/storage/client_ips.py b/synapse/storage/client_ips.py index 5bed255eb..f95921d73 100644 --- a/synapse/storage/client_ips.py +++ b/synapse/storage/client_ips.py @@ -90,9 +90,6 @@ class ClientIpStore(background_updates.BackgroundUpdateStore): are (user_id, device_id) tuples. The values are also dicts, with keys giving the column names """ - if not devices: - defer.returnValue({}) - res = yield self.runInteraction( "get_last_client_ip_by_device", self._get_last_client_ip_by_device_txn, From 85657eedf8ce54acf0c78e673e58dd33e12c7f75 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 11 Apr 2017 16:24:31 +0100 Subject: [PATCH 3/3] Bail on where clause instead --- synapse/storage/client_ips.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/synapse/storage/client_ips.py b/synapse/storage/client_ips.py index f95921d73..b01f0046e 100644 --- a/synapse/storage/client_ips.py +++ b/synapse/storage/client_ips.py @@ -90,6 +90,7 @@ class ClientIpStore(background_updates.BackgroundUpdateStore): are (user_id, device_id) tuples. The values are also dicts, with keys giving the column names """ + res = yield self.runInteraction( "get_last_client_ip_by_device", self._get_last_client_ip_by_device_txn, @@ -109,9 +110,6 @@ class ClientIpStore(background_updates.BackgroundUpdateStore): @classmethod def _get_last_client_ip_by_device_txn(cls, txn, devices, retcols): - if not devices: - return [] - where_clauses = [] bindings = [] for (user_id, device_id) in devices: @@ -122,6 +120,9 @@ class ClientIpStore(background_updates.BackgroundUpdateStore): where_clauses.append("(user_id = ? AND device_id = ?)") bindings.extend((user_id, device_id)) + if not where_clauses: + return [] + inner_select = ( "SELECT MAX(last_seen) mls, user_id, device_id FROM user_ips " "WHERE %(where)s "