From 015b87ee9976f15f8c8e0616b952d41a28ae8c16 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 16 Aug 2023 19:32:43 +0000 Subject: [PATCH] performance / cosmetic: * js: use .call instead of .bind when possible * when running without e2d, the message on startup regarding unfinished uploads didn't show the correct filesystem path --- copyparty/up2k.py | 14 +++++++------- copyparty/web/baguettebox.js | 4 ++-- copyparty/web/browser.js | 6 +++--- copyparty/web/up2k.js | 6 +++--- copyparty/web/util.js | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 8f61632b..cccc521a 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -791,9 +791,9 @@ class Up2k(object): reg = {} drp = None - path = os.path.join(histpath, "up2k.snap") - if bos.path.exists(path): - with gzip.GzipFile(path, "rb") as f: + snap = os.path.join(histpath, "up2k.snap") + if bos.path.exists(snap): + with gzip.GzipFile(snap, "rb") as f: j = f.read().decode("utf-8") reg2 = json.loads(j) @@ -804,20 +804,20 @@ class Up2k(object): pass for k, job in reg2.items(): - path = djoin(job["ptop"], job["prel"], job["name"]) - if bos.path.exists(path): + fp = djoin(job["ptop"], job["prel"], job["name"]) + if bos.path.exists(fp): reg[k] = job job["poke"] = time.time() job["busy"] = {} else: - self.log("ign deleted file in snap: [{}]".format(path)) + self.log("ign deleted file in snap: [{}]".format(fp)) if drp is None: drp = [k for k, v in reg.items() if not v.get("need", [])] else: drp = [x for x in drp if x in reg] - t = "loaded snap {} |{}| ({})".format(path, len(reg.keys()), len(drp or [])) + t = "loaded snap {} |{}| ({})".format(snap, len(reg.keys()), len(drp or [])) ta = [t] + self._vis_reg_progress(reg) self.log("\n".join(ta)) diff --git a/copyparty/web/baguettebox.js b/copyparty/web/baguettebox.js index 681a1cf8..10a318c8 100644 --- a/copyparty/web/baguettebox.js +++ b/copyparty/web/baguettebox.js @@ -310,7 +310,7 @@ window.baguetteBox = (function () { options = {}; setOptions(o); if (tt.en) - tt.show.bind(this)(); + tt.show.call(this); } function setVmode() { @@ -356,7 +356,7 @@ window.baguetteBox = (function () { setVmode(); if (tt.en) - tt.show.bind(this)(); + tt.show.call(this); } function findfile() { diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 73c65d1b..43f6c59e 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -4310,14 +4310,14 @@ var thegrid = (function () { if (ctrl(e) && !treectl.csel && !r.sel) return true; - return gclick.bind(this)(e, false); + return gclick.call(this, e, false); } function gclick2(e) { if (ctrl(e) || !r.sel) return true; - return gclick.bind(this)(e, true); + return gclick.call(this, e, true); } function gclick(e, dbl) { @@ -4332,7 +4332,7 @@ var thegrid = (function () { tr = td.parentNode; if ((r.sel && !dbl && !ctrl(e)) || (treectl.csel && (e.shiftKey || ctrl(e)))) { - td.onclick.bind(td)(e); + td.onclick.call(td, e); if (e.shiftKey) return r.loadsel(); clmod(this, 'sel', clgot(tr, 'sel')); diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index da359d33..424bfaf9 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -971,7 +971,7 @@ function up2k_init(subtle) { if (++nenters <= 0) nenters = 1; - if (onover.bind(this)(e)) + if (onover.call(this, e)) return true; var mup, up = QS('#up_zd'); @@ -995,7 +995,7 @@ function up2k_init(subtle) { function onoverb(e) { // zones are alive; disable cuo2duo branch document.body.ondragover = document.body.ondrop = null; - return onover.bind(this)(e); + return onover.call(this, e); } function onover(e) { return onovercmn(this, e, false); @@ -1106,7 +1106,7 @@ function up2k_init(subtle) { function gotfile(e) { ev(e); nenters = 0; - offdrag.bind(this)(); + offdrag.call(this); var dz = this && this.getAttribute('id'); if (!dz && e && e.clientY) // cuo2duo fallback diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 46642ebf..b40b0990 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1165,7 +1165,7 @@ var tt = (function () { var prev = null; r.cshow = function () { if (this !== prev) - r.show.bind(this)(); + r.show.call(this); prev = this; }; @@ -1177,7 +1177,7 @@ var tt = (function () { return; if (Date.now() - r.lvis < 400) - return r.show.bind(this)(); + return r.show.call(this); tev = setTimeout(r.show.bind(this), 800); if (TOUCH)