From 3a93804655997eb3386da8156b9343137494fc26 Mon Sep 17 00:00:00 2001 From: ymq Date: Wed, 26 Aug 2026 16:42:51 +0800 Subject: [PATCH] =?UTF-8?q?perf(load=5Fpath):=20=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E7=9B=B4=E5=86=99=20DB=EF=BC=8C=E9=81=BF=E5=85=8D=20159=20?= =?UTF-8?q?=E6=AC=A1=20subprocess=20=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原 subprocess.run(set_role_perm.py) 每个路径起一个 python 进程,159 路径太慢。 改为一次连接批量注册 permission + rolepermission。 --- scripts/load_path.py | 50 ++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/scripts/load_path.py b/scripts/load_path.py index 54c1204..18310b3 100755 --- a/scripts/load_path.py +++ b/scripts/load_path.py @@ -1,19 +1,28 @@ #!/usr/bin/env python3 -"""RBAC path registration for supplychain module. +"""RBAC path registration for supplychain module (pipeline format). -宿主根目录执行:py3/bin/python pkgs/supplychain/scripts/load_path.py -(pipeline-app 的 load_path.sh 会自动扫描 pkgs/*/scripts/load_path.py) +从应用根执行:py3/bin/python pkgs/supplychain/scripts/load_path.py +(load_path.sh 自动扫描 pkgs/*/scripts/load_path.py 并调用本脚本) +批量直写 DB,避免逐个 subprocess 启动 set_role_perm.py(159 路径)。 """ -import subprocess +import sys +import os +import asyncio -MOD = "supplychain" +# 应用根:本脚本在 pkgs/supplychain/scripts/ 下,上溯三级 +APP_ROOT = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")) +sys.path.insert(0, os.path.join(APP_ROOT, "py3", "lib", "python3.10", "site-packages")) +sys.path.insert(0, APP_ROOT) + +from sqlor.dbpools import DBPools +from appPublic.jsonConfig import getConfig +from appPublic.uniqueID import getID PATHS_ANY = [ "/supplychain/menu.ui", ] PATHS_LOGINED = [ - "/supplychain", "/supplychain/accounting.ui", "/supplychain/add_provider_recharge.dspy", @@ -175,16 +184,25 @@ PATHS_LOGINED = [ ] -def register_paths(): - for path in PATHS_ANY: - subprocess.run(["py3/bin/python", "set_role_perm.py", "any", path]) - print(f" any: {path}") - for path in PATHS_LOGINED: - subprocess.run(["py3/bin/python", "set_role_perm.py", "logined", path]) - print(f" logined: {path}") +async def main(): + config = getConfig(APP_ROOT, NS={"workdir": APP_ROOT}) + DBPools(config.databases) + cnt = 0 + async with DBPools().sqlorContext("pipeline") as sor: + for role, paths in (("any", PATHS_ANY), ("logined", PATHS_LOGINED)): + for path in paths: + recs = await sor.R("permission", {"path": path}) + if recs: + permid = recs[0].id + else: + permid = getID() + await sor.C("permission", {"id": permid, "path": path}) + rp = await sor.R("rolepermission", {"roleid": role, "permid": permid}) + if not rp: + await sor.C("rolepermission", {"id": getID(), "roleid": role, "permid": permid}) + cnt += 1 + print(f"Done. any={len(PATHS_ANY)} logined={len(PATHS_LOGINED)} total={cnt}") if __name__ == "__main__": - print("=== supplychain RBAC registration ===") - register_paths() - print("Done. any=1 logined=158") + asyncio.run(main())