Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove unnecessary SystemRandom from SQLBaseStore (#9987)
Browse files Browse the repository at this point in the history
It's not obvious that instances of SQLBaseStore each need their own
instances of random.SystemRandom(); let's just use random directly.

Introduced by 5283988

Signed-off-by: Dan Callahan <danc@element.io>
  • Loading branch information
callahad authored May 14, 2021
1 parent ebdef25 commit 52ed965
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/9987.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unnecessary property from SQLBaseStore.
2 changes: 0 additions & 2 deletions synapse/storage/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import random
from abc import ABCMeta
from typing import TYPE_CHECKING, Any, Collection, Iterable, Optional, Union

Expand Down Expand Up @@ -44,7 +43,6 @@ def __init__(self, database: DatabasePool, db_conn: Connection, hs: "HomeServer"
self._clock = hs.get_clock()
self.database_engine = database.engine
self.db_pool = database
self.rand = random.SystemRandom()

def process_replication_rows(
self,
Expand Down
3 changes: 2 additions & 1 deletion synapse/storage/databases/main/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import random
import re
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -997,7 +998,7 @@ def set_expiration_date_for_user_txn(self, txn, user_id, use_delta=False):
expiration_ts = now_ms + self._account_validity_period

if use_delta:
expiration_ts = self.rand.randrange(
expiration_ts = random.randrange(
expiration_ts - self._account_validity_startup_job_max_delta,
expiration_ts,
)
Expand Down

0 comments on commit 52ed965

Please sign in to comment.