From 9c52c1dc0615dc051fc0e6a62c96696deee36fe1 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Thu, 17 Mar 2022 13:42:36 +0000 Subject: Add assertions that some MAU updating methods only run on the background worker Currently don't hold, but it's preparation for the next step --- synapse/storage/databases/main/monthly_active_users.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/synapse/storage/databases/main/monthly_active_users.py b/synapse/storage/databases/main/monthly_active_users.py index e9a0cdc6be..e10be257a9 100644 --- a/synapse/storage/databases/main/monthly_active_users.py +++ b/synapse/storage/databases/main/monthly_active_users.py @@ -230,6 +230,8 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore): ): super().__init__(database, db_conn, hs) + self._update_on_this_worker = hs.config.worker.run_background_tasks + self._mau_stats_only = hs.config.server.mau_stats_only # Do not add more reserved users than the total allowable number @@ -250,6 +252,9 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore): txn (cursor): threepids (list[dict]): List of threepid dicts to reserve """ + assert ( + self._update_on_this_worker + ), "This worker is not designated to update MAUs" # XXX what is this function trying to achieve? It upserts into # monthly_active_users for each *registered* reserved mau user, but why? @@ -283,6 +288,10 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore): Args: user_id: user to add/update """ + assert ( + self._update_on_this_worker + ), "This worker is not designated to update MAUs" + # Support user never to be included in MAU stats. Note I can't easily call this # from upsert_monthly_active_user_txn because then I need a _txn form of # is_support_user which is complicated because I want to cache the result. @@ -316,6 +325,9 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore): txn (cursor): user_id (str): user to add/update """ + assert ( + self._update_on_this_worker + ), "This worker is not designated to update MAUs" # Am consciously deciding to lock the table on the basis that is ought # never be a big table and alternative approaches (batching multiple @@ -343,6 +355,10 @@ class MonthlyActiveUsersStore(MonthlyActiveUsersWorkerStore): Args: user_id(str): the user_id to query """ + assert ( + self._update_on_this_worker + ), "This worker is not designated to update MAUs" + if self._limit_usage_by_mau or self._mau_stats_only: # Trial users and guests should not be included as part of MAU group is_guest = await self.is_guest(user_id) -- cgit 1.4.1