diff options
author | Erik Johnston <erik@matrix.org> | 2019-05-31 12:11:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-31 12:11:56 +0100 |
commit | 58cce39f3a91d81f3c994d510b0a283efd468ec7 (patch) | |
tree | 5d3edea845bd4347dd1c77684dbc1c9a8f0c30c0 /synapse/storage | |
parent | Merge pull request #5300 from matrix-org/rav/server_keys/06-fix-serverkeys-ha... (diff) | |
parent | Sample config (diff) | |
download | synapse-58cce39f3a91d81f3c994d510b0a283efd468ec7.tar.xz |
Merge pull request #5276 from matrix-org/babolivier/account_validity_job_delta
Allow configuring a range for the account validity startup job
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/_base.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 3fe827cd43..52891bb9eb 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -16,6 +16,7 @@ # limitations under the License. import itertools import logging +import random import sys import threading import time @@ -247,6 +248,8 @@ class SQLBaseStore(object): self._check_safe_to_upsert, ) + self.rand = random.SystemRandom() + if self._account_validity.enabled: self._clock.call_later( 0.0, @@ -308,21 +311,36 @@ class SQLBaseStore(object): res = self.cursor_to_dict(txn) if res: for user in res: - self.set_expiration_date_for_user_txn(txn, user["name"]) + self.set_expiration_date_for_user_txn( + txn, + user["name"], + use_delta=True, + ) yield self.runInteraction( "get_users_with_no_expiration_date", select_users_with_no_expiration_date_txn, ) - def set_expiration_date_for_user_txn(self, txn, user_id): + def set_expiration_date_for_user_txn(self, txn, user_id, use_delta=False): """Sets an expiration date to the account with the given user ID. Args: user_id (str): User ID to set an expiration date for. + use_delta (bool): If set to False, the expiration date for the user will be + now + validity period. If set to True, this expiration date will be a + random value in the [now + period - d ; now + period] range, d being a + delta equal to 10% of the validity period. """ now_ms = self._clock.time_msec() expiration_ts = now_ms + self._account_validity.period + + if use_delta: + expiration_ts = self.rand.randrange( + expiration_ts - self._account_validity.startup_job_max_delta, + expiration_ts, + ) + self._simple_insert_txn( txn, "account_validity", |