From 0c43b592dc6c70a7b37caca0f6a66fdb9fe2c20e Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 22 Nov 2024 22:24:56 +0000 Subject: [PATCH] pave the way for more ux volflags makes directory listings a tiny bit faster, about 7% or so --- copyparty/authsrv.py | 65 ++++++++++++++++++++++++++++++++++++++ copyparty/httpcli.py | 47 ++------------------------- copyparty/web/browser.html | 5 ++- copyparty/web/browser.js | 2 ++ copyparty/web/util.js | 11 +++++-- 5 files changed, 81 insertions(+), 49 deletions(-) diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 7743f060..d6ad2cdf 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -367,6 +367,8 @@ class VFS(object): self.ahtml: dict[str, list[str]] = {} self.aadmin: dict[str, list[str]] = {} self.adot: dict[str, list[str]] = {} + self.js_ls = {} + self.js_htm = "" if realpath: rp = realpath + ("" if realpath.endswith(os.sep) else os.sep) @@ -2304,6 +2306,69 @@ class AuthSrv(object): cur.close() db.close() + self.js_ls = {} + self.js_htm = {} + for vn in self.vfs.all_nodes.values(): + vf = vn.flags + vn.js_ls = { + "idx": "e2d" in vf, + "itag": "e2t" in vf, + "dnsort": "nsort" in vf, + "dsort": vf["sort"], + "dcrop": vf["crop"], + "dth3x": vf["th3x"], + "u2ts": vf["u2ts"], + "frand": bool(vf.get("rand")), + "lifetime": vf.get("lifetime") or 0, + "unlist": vf.get("unlist") or "", + } + js_htm = { + "s_name": self.args.bname, + "have_up2k_idx": "e2d" in vf, + "have_acode": not self.args.no_acode, + "have_shr": self.args.shr, + "have_zip": not self.args.no_zip, + "have_mv": not self.args.no_mv, + "have_del": not self.args.no_del, + "have_unpost": int(self.args.unpost), + "have_emp": self.args.emp, + "sb_md": "" if "no_sb_md" in vf else (vf.get("md_sbf") or "y"), + "txt_ext": self.args.textfiles.replace(",", " "), + "def_hcols": list(vf.get("mth") or []), + "unlist0": vf.get("unlist") or "", + "dgrid": "grid" in vf, + "dgsel": "gsel" in vf, + "dnsort": "nsort" in vf, + "dsort": vf["sort"], + "dcrop": vf["crop"], + "dth3x": vf["th3x"], + "dvol": self.args.au_vol, + "idxh": int(self.args.ih), + "themes": self.args.themes, + "turbolvl": self.args.turbo, + "u2j": self.args.u2j, + "u2sz": self.args.u2sz, + "u2ts": vf["u2ts"], + "frand": bool(vf.get("rand")), + "lifetime": vn.js_ls["lifetime"], + "u2sort": self.args.u2sort, + } + vn.js_htm = json.dumps(js_htm) + + vols = list(vfs.all_nodes.values()) + if enshare: + assert shv # type: ignore # !rm + vols.append(shv) + vols.extend(list(shv.nodes.values())) + + for vol in vols: + dbv = vol.get_dbv("")[0] + vol.js_ls = vol.js_ls or dbv.js_ls or {} + vol.js_htm = vol.js_htm or dbv.js_htm or "{}" + + zs = str(vol.flags.get("tcolor") or self.args.tcolor) + vol.flags["tcolor"] = zs.lstrip("#") + def load_sessions(self, quiet=False) -> None: # mutex me if self.args.no_ses: diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 3aa5bb6b..8c3e162a 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -248,7 +248,6 @@ class HttpCli(object): ka["ts"] = self.conn.hsrv.cachebuster() ka["lang"] = self.args.lang ka["favico"] = self.args.favico - ka["s_name"] = self.args.bname ka["s_doctitle"] = self.args.doctitle ka["tcolor"] = self.vn.flags["tcolor"] @@ -5496,63 +5495,28 @@ class HttpCli(object): is_js = False vf = vn.flags - unlist = vf.get("unlist", "") ls_ret = { "dirs": [], "files": [], "taglist": [], "srvinf": srv_infot, "acct": self.uname, - "idx": e2d, - "itag": e2t, - "dnsort": "nsort" in vf, - "dsort": vf["sort"], - "dcrop": vf["crop"], - "dth3x": vf["th3x"], - "u2ts": vf["u2ts"], - "lifetime": vn.flags.get("lifetime") or 0, - "frand": bool(vn.flags.get("rand")), - "unlist": unlist, "perms": perms, + "cfg": vn.js_ls, } cgv = { "ls0": None, "acct": self.uname, "perms": perms, - "u2ts": vf["u2ts"], - "lifetime": ls_ret["lifetime"], - "frand": bool(vn.flags.get("rand")), - "def_hcols": [], - "have_emp": self.args.emp, - "have_up2k_idx": e2d, - "have_acode": (not self.args.no_acode), - "have_mv": (not self.args.no_mv), - "have_del": (not self.args.no_del), - "have_zip": (not self.args.no_zip), - "have_shr": self.args.shr, - "have_unpost": int(self.args.unpost), - "sb_md": "" if "no_sb_md" in vf else (vf.get("md_sbf") or "y"), - "dgrid": "grid" in vf, - "dgsel": "gsel" in vf, - "dnsort": "nsort" in vf, - "dsort": vf["sort"], - "dcrop": vf["crop"], - "dth3x": vf["th3x"], - "dvol": self.args.au_vol, - "themes": self.args.themes, - "turbolvl": self.args.turbo, - "u2j": self.args.u2j, - "u2sz": self.args.u2sz, - "idxh": int(self.args.ih), - "u2sort": self.args.u2sort, } j2a = { + "cgv1": vn.js_htm, "cgv": cgv, "vpnodes": vpnodes, "files": [], "ls0": None, "taglist": [], - "have_tags_idx": e2t, + "have_tags_idx": int(e2t), "have_b_u": (self.can_write and self.uparam.get("b") == "u"), "sb_lg": "" if "no_sb_lg" in vf else (vf.get("lg_sbf") or "y"), "url_suf": url_suf, @@ -5924,17 +5888,12 @@ class HttpCli(object): "dirs": dirs, "files": files, "taglist": taglist, - "unlist": unlist, } j2a["files"] = [] else: j2a["files"] = dirs + files j2a["taglist"] = taglist - j2a["txt_ext"] = self.args.textfiles.replace(",", " ") - - if "mth" in vn.flags: - j2a["def_hcols"] = list(vn.flags["mth"]) if add_og and "raw" not in self.uparam: j2a["this"] = self diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index 78be327d..46a5a6ea 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -132,16 +132,15 @@