From 55c74ad164633a0a64dceb51f7f534da0422cbb5 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 26 Apr 2023 18:55:53 +0000 Subject: [PATCH] 30% faster folder listings (wtf...) --- .gitignore | 1 + copyparty/httpcli.py | 9 ++++++++- copyparty/svchub.py | 18 +++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 7be5af78..71617404 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ up.*.txt .hist/ scripts/docker/*.out scripts/docker/*.err +/perf.* # nix build output link result diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index f0198ca8..ee841dad 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -3604,7 +3604,14 @@ class HttpCli(object): sz = inf.st_size zd = datetime.utcfromtimestamp(linf.st_mtime) - dt = zd.strftime("%Y-%m-%d %H:%M:%S") + dt = "%04d-%02d-%02d %02d:%02d:%02d" % ( + zd.year, + zd.month, + zd.day, + zd.hour, + zd.minute, + zd.second, + ) try: ext = "---" if is_dir else fn.rsplit(".", 1)[1] diff --git a/copyparty/svchub.py b/copyparty/svchub.py index a0a7d9ec..dfa654c3 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -647,8 +647,14 @@ class SvcHub(object): return with self.log_mutex: - ts = datetime.utcnow().strftime("%Y-%m%d-%H%M%S.%f")[:-3] - self.logf.write("@{} [{}\033[0m] {}\n".format(ts, src, msg)) + zd = datetime.utcnow() + ts = "%04d-%04d-%06d.%03d" % ( + zd.year, + zd.month * 100 + zd.day, + (zd.hour * 100 + zd.minute) * 100 + zd.second, + zd.microsecond // 1000, + ) + self.logf.write("@%s [%s\033[0m] %s\n" % (ts, src, msg)) now = time.time() if now >= self.next_day: @@ -693,7 +699,13 @@ class SvcHub(object): else: msg = "{}{}\033[0m".format(c, msg) - ts = datetime.utcfromtimestamp(now).strftime("%H:%M:%S.%f")[:-3] + zd = datetime.utcfromtimestamp(now) + ts = "%02d:%02d:%02d.%03d" % ( + zd.hour, + zd.minute, + zd.second, + zd.microsecond // 1000, + ) msg = fmt.format(ts, src, msg) try: print(msg, end="")