From ed952ffdda1241c2d96969bba36894300e09d30a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 10 Mar 2022 11:26:51 -0800 Subject: [PATCH] Use getrandbits instead of passwordy strings for savepoint ids. Better perf, why not. --- voussoirkit/worms.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 88b61f3..2d66478 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -3,15 +3,17 @@ Worms is an SQL ORM with the strength and resilience of the humble earthworm. ''' import abc import functools +import random import re import typing -from voussoirkit import passwordy from voussoirkit import sqlhelpers from voussoirkit import vlogging log = vlogging.getLogger(__name__, 'worms') +RNG = random.SystemRandom() + class WormException(Exception): pass @@ -112,7 +114,7 @@ class Database(metaclass=abc.ABCMeta): while len(self.on_commit_queue) > 0: task = self.on_commit_queue.pop(-1) - if isinstance(task, str): + if isinstance(task, int): # savepoints. continue args = task.get('args', []) @@ -309,7 +311,7 @@ class Database(metaclass=abc.ABCMeta): task = self.on_rollback_queue.pop(-1) if task == savepoint: break - if isinstance(task, str): + if isinstance(task, int): # Intermediate savepoints. continue args = task.get('args', []) @@ -329,7 +331,7 @@ class Database(metaclass=abc.ABCMeta): self.on_commit_queue.clear() def savepoint(self, message=None) -> str: - savepoint_id = passwordy.random_hex(length=16) + savepoint_id = RNG.getrandbits(32) if message: log.log(5, 'Savepoint %s for %s.', savepoint_id, message) else: