From 1c9c17fb9b36654b98cb121914ee248a6717e848 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 31 Aug 2024 21:54:47 +0000 Subject: [PATCH] optimize test_dedup.py * 7.71s originally * 4.51s with fstab reuse * 4.34s without db_wd * 4.02s with no pp start * 3.73s with Cfg reuse --- copyparty/up2k.py | 6 +++++- copyparty/util.py | 1 - tests/test_dedup.py | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 85d52cae..263b9952 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -749,6 +749,8 @@ class Up2k(object): continue self.pp = ProgressPrinter(self.log, self.args) + if not self.hub.is_dut: + self.pp.start() break @@ -2353,7 +2355,9 @@ class Up2k(object): def _open_db_wd(self, db_path: str) -> "sqlite3.Cursor": ok: list[int] = [] - Daemon(self._open_db_timeout, "opendb_watchdog", [db_path, ok]) + if not self.hub.is_dut: + Daemon(self._open_db_timeout, "opendb_watchdog", [db_path, ok]) + try: return self._open_db(db_path) finally: diff --git a/copyparty/util.py b/copyparty/util.py index eb543434..b6d23733 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -915,7 +915,6 @@ class ProgressPrinter(threading.Thread): self.msg = "" self.end = False self.n = -1 - self.start() def run(self) -> None: sigblock() diff --git a/tests/test_dedup.py b/tests/test_dedup.py index cc480e3b..c92aea5d 100644 --- a/tests/test_dedup.py +++ b/tests/test_dedup.py @@ -54,18 +54,23 @@ class TestDedup(unittest.TestCase): # 3072 uploads in total self.ctr = 3072 self.conn = None + fstab = None for e2d in [True, False]: + self.args = Cfg(v=[".::A"], a=[], e2d=e2d) for dn1, fn1, f1 in product(dirnames, filenames, files): for dn2, fn2, f2 in product(dirnames, filenames, files): for dn3, fn3, f3 in product(dirnames, filenames, files): self.reset() if self.conn: + fstab = self.conn.hsrv.hub.up2k.fstab self.conn.hsrv.hub.up2k.shutdown() - self.args = Cfg(v=[".::A"], a=[], e2d=e2d) self.asrv = AuthSrv(self.args, self.log) self.conn = tu.VHttpConn( self.args, self.asrv, self.log, b"", True ) + if fstab: + self.conn.hsrv.hub.up2k.fstab = fstab + self.do_post(dn1, fn1, f1, True) self.do_post(dn2, fn2, f2, False) self.do_post(dn3, fn3, f3, False)