diff options
author | Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> | 2020-12-11 11:42:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 10:42:47 +0000 |
commit | 0a34cdfc6682c2654c745c4d7c2f5ffd1865dbc8 (patch) | |
tree | d88b4fe4410945941be114faea26b71818e8ff33 /synapse/storage/databases | |
parent | Don't ratelimit autojoining of rooms (#8921) (diff) | |
download | synapse-0a34cdfc6682c2654c745c4d7c2f5ffd1865dbc8.tar.xz |
Add number of local devices to Room Details Admin API (#8886)
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r-- | synapse/storage/databases/main/devices.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py index dfb4f87b8f..9097677648 100644 --- a/synapse/storage/databases/main/devices.py +++ b/synapse/storage/databases/main/devices.py @@ -57,6 +57,38 @@ class DeviceWorkerStore(SQLBaseStore): self._prune_old_outbound_device_pokes, 60 * 60 * 1000 ) + async def count_devices_by_users(self, user_ids: Optional[List[str]] = None) -> int: + """Retrieve number of all devices of given users. + Only returns number of devices that are not marked as hidden. + + Args: + user_ids: The IDs of the users which owns devices + Returns: + Number of devices of this users. + """ + + def count_devices_by_users_txn(txn, user_ids): + sql = """ + SELECT count(*) + FROM devices + WHERE + hidden = '0' AND + """ + + clause, args = make_in_list_sql_clause( + txn.database_engine, "user_id", user_ids + ) + + txn.execute(sql + clause, args) + return txn.fetchone()[0] + + if not user_ids: + return 0 + + return await self.db_pool.runInteraction( + "count_devices_by_users", count_devices_by_users_txn, user_ids + ) + async def get_device(self, user_id: str, device_id: str) -> Dict[str, Any]: """Retrieve a device. Only returns devices that are not marked as hidden. |