mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-13 09:32:12 -04:00
Add storage and module API methods to get monthly active users and their appservices (#12838)
This commit is contained in:
parent
3503f42741
commit
a7da00d4f7
4 changed files with 149 additions and 0 deletions
|
@ -122,6 +122,51 @@ class MonthlyActiveUsersWorkerStore(RegistrationWorkerStore):
|
|||
"count_users_by_service", _count_users_by_service
|
||||
)
|
||||
|
||||
async def get_monthly_active_users_by_service(
|
||||
self, start_timestamp: Optional[int] = None, end_timestamp: Optional[int] = None
|
||||
) -> List[Tuple[str, str]]:
|
||||
"""Generates list of monthly active users and their services.
|
||||
Please see "get_monthly_active_count_by_service" docstring for more details
|
||||
about services.
|
||||
|
||||
Arguments:
|
||||
start_timestamp: If specified, only include users that were first active
|
||||
at or after this point
|
||||
end_timestamp: If specified, only include users that were first active
|
||||
at or before this point
|
||||
|
||||
Returns:
|
||||
A list of tuples (appservice_id, user_id). "native" is emitted as the
|
||||
appservice for users that don't come from appservices (i.e. native Matrix
|
||||
users).
|
||||
|
||||
"""
|
||||
if start_timestamp is not None and end_timestamp is not None:
|
||||
where_clause = 'WHERE "timestamp" >= ? and "timestamp" <= ?'
|
||||
query_params = [start_timestamp, end_timestamp]
|
||||
elif start_timestamp is not None:
|
||||
where_clause = 'WHERE "timestamp" >= ?'
|
||||
query_params = [start_timestamp]
|
||||
elif end_timestamp is not None:
|
||||
where_clause = 'WHERE "timestamp" <= ?'
|
||||
query_params = [end_timestamp]
|
||||
else:
|
||||
where_clause = ""
|
||||
query_params = []
|
||||
|
||||
def _list_users(txn: LoggingTransaction) -> List[Tuple[str, str]]:
|
||||
sql = f"""
|
||||
SELECT COALESCE(appservice_id, 'native'), user_id
|
||||
FROM monthly_active_users
|
||||
LEFT JOIN users ON monthly_active_users.user_id=users.name
|
||||
{where_clause};
|
||||
"""
|
||||
|
||||
txn.execute(sql, query_params)
|
||||
return cast(List[Tuple[str, str]], txn.fetchall())
|
||||
|
||||
return await self.db_pool.runInteraction("list_users", _list_users)
|
||||
|
||||
async def get_registered_reserved_users(self) -> List[str]:
|
||||
"""Of the reserved threepids defined in config, retrieve those that are associated
|
||||
with registered users
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue