perf(load_path): 批量直写 DB,避免 159 次 subprocess 启动
原 subprocess.run(set_role_perm.py) 每个路径起一个 python 进程,159 路径太慢。 改为一次连接批量注册 permission + rolepermission。
This commit is contained in:
parent
ebff8d7f08
commit
3a93804655
@ -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())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user