diff --git a/changelog.d/12251.feature b/changelog.d/12251.feature index 82b9e82f868b..ba9ede03c68f 100644 --- a/changelog.d/12251.feature +++ b/changelog.d/12251.feature @@ -1 +1 @@ -Move `update_client_ip` background job from the main process to the background worker. \ No newline at end of file +Offload the `update_client_ip` background job from the main process to the background worker, when using Redis-based replication. diff --git a/synapse/storage/databases/main/client_ips.py b/synapse/storage/databases/main/client_ips.py index 4298d9576cdd..8480ea4e1c3c 100644 --- a/synapse/storage/databases/main/client_ips.py +++ b/synapse/storage/databases/main/client_ips.py @@ -408,7 +408,13 @@ def __init__( ): super().__init__(database, db_conn, hs) - self._update_on_this_worker = hs.config.worker.run_background_tasks + if hs.config.redis.redis_enabled: + # If we're using Redis, we can shift this update process off to + # the background worker + self._update_on_this_worker = hs.config.worker.run_background_tasks + else: + # If we're NOT using Redis, this must be handled by the master + self._update_on_this_worker = hs.get_instance_name() == "master" self.user_ips_max_age = hs.config.server.user_ips_max_age diff --git a/synapse/storage/databases/main/monthly_active_users.py b/synapse/storage/databases/main/monthly_active_users.py index de13dea21a7e..4f1c22c71b0a 100644 --- a/synapse/storage/databases/main/monthly_active_users.py +++ b/synapse/storage/databases/main/monthly_active_users.py @@ -46,7 +46,13 @@ def __init__( self._clock = hs.get_clock() self.hs = hs - self._update_on_this_worker = hs.config.worker.run_background_tasks + if hs.config.redis.redis_enabled: + # If we're using Redis, we can shift this update process off to + # the background worker + self._update_on_this_worker = hs.config.worker.run_background_tasks + else: + # If we're NOT using Redis, this must be handled by the master + self._update_on_this_worker = hs.get_instance_name() == "master" self._limit_usage_by_mau = hs.config.server.limit_usage_by_mau self._max_mau_value = hs.config.server.max_mau_value