diff options
author | Azrenbeth <7782548+Azrenbeth@users.noreply.github.com> | 2021-09-28 16:15:58 +0100 |
---|---|---|
committer | Azrenbeth <7782548+Azrenbeth@users.noreply.github.com> | 2021-09-28 16:15:58 +0100 |
commit | db6cc8f35b739b4db84a58f5226f79e6fad61978 (patch) | |
tree | d76d4fa3f80eda9d28b999fab5e1cfc349da09c7 /synapse/storage/databases/main/client_ips.py | |
parent | Tidy up documentation a bit (diff) | |
parent | Drop backwards-compatibility support for "outlier" (#10903) (diff) | |
download | synapse-db6cc8f35b739b4db84a58f5226f79e6fad61978.tar.xz |
Merge remote-tracking branch 'origin/develop' into azren/compressor_integration
Diffstat (limited to 'synapse/storage/databases/main/client_ips.py')
-rw-r--r-- | synapse/storage/databases/main/client_ips.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/synapse/storage/databases/main/client_ips.py b/synapse/storage/databases/main/client_ips.py index 7a98275d92..7e33ae578c 100644 --- a/synapse/storage/databases/main/client_ips.py +++ b/synapse/storage/databases/main/client_ips.py @@ -555,8 +555,11 @@ class ClientIpStore(ClientIpWorkerStore): return ret async def get_user_ip_and_agents( - self, user: UserID + self, user: UserID, since_ts: int = 0 ) -> List[Dict[str, Union[str, int]]]: + """ + Fetch IP/User Agent connection since a given timestamp. + """ user_id = user.to_string() results = {} @@ -568,13 +571,23 @@ class ClientIpStore(ClientIpWorkerStore): ) = key if uid == user_id: user_agent, _, last_seen = self._batch_row_update[key] - results[(access_token, ip)] = (user_agent, last_seen) + if last_seen >= since_ts: + results[(access_token, ip)] = (user_agent, last_seen) - rows = await self.db_pool.simple_select_list( - table="user_ips", - keyvalues={"user_id": user_id}, - retcols=["access_token", "ip", "user_agent", "last_seen"], - desc="get_user_ip_and_agents", + def get_recent(txn): + txn.execute( + """ + SELECT access_token, ip, user_agent, last_seen FROM user_ips + WHERE last_seen >= ? AND user_id = ? + ORDER BY last_seen + DESC + """, + (since_ts, user_id), + ) + return txn.fetchall() + + rows = await self.db_pool.runInteraction( + desc="get_user_ip_and_agents", func=get_recent ) results.update( |