summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-03-17 13:42:36 +0000
committerOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-03-17 13:42:36 +0000
commit9c52c1dc0615dc051fc0e6a62c96696deee36fe1 (patch)
tree99d41aa42684dec56929f8a9a5a9e9bcb686a40b
parentMerge branch 'release-v1.55' into develop (diff)
downloadsynapse-9c52c1dc0615dc051fc0e6a62c96696deee36fe1.tar.xz
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
-rw-r--r--synapse/storage/databases/main/monthly_active_users.py16
1 files changed, 16 insertions, 0 deletions
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)