浏览代码

Merge pull request #16465 from resilient-tech/refactor-get_assets_json

perf: cache parsed `assets_json` instead of string
version-14
gavin 3 年前
committed by GitHub
父节点
当前提交
590a25ef78
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 1 个文件被更改,包括 12 次插入26 次删除
  1. +12
    -26
      frappe/utils/__init__.py

+ 12
- 26
frappe/utils/__init__.py 查看文件

@@ -793,38 +793,24 @@ def get_build_version():
def get_assets_json():
if not hasattr(frappe.local, "assets_json"):
cache = frappe.cache()
assets = None

# using .get instead of .get_value to avoid pickle.loads
try:
if not frappe.conf.developer_mode:
assets_json = cache.get("assets_json").decode('utf-8')
else:
assets_json = None
except (UnicodeDecodeError, AttributeError, ConnectionError):
assets_json = None
if not frappe.conf.developer_mode:
assets = cache.get_value("assets_json", shared=True)

if not assets_json:
if not assets:
# get merged assets.json and assets-rtl.json
assets_dict = frappe.parse_json(
frappe.read_file("assets/assets.json")
)

assets_rtl = frappe.read_file("assets/assets-rtl.json")
if assets_rtl:
assets_dict.update(
frappe.parse_json(assets_rtl)
)
frappe.local.assets_json = frappe.as_json(assets_dict)
assets = frappe.parse_json(frappe.read_file("assets/assets.json"))

if assets_rtl := frappe.read_file("assets/assets-rtl.json"):
assets.update(frappe.parse_json(assets_rtl))

# save in cache
cache.set_value("assets_json", frappe.local.assets_json,
shared=True)
cache.set_value("assets_json", assets, shared=True)

return assets_dict
else:
# from cache, decode and send
frappe.local.assets_json = frappe.safe_decode(assets_json)
frappe.local.assets_json = assets

return frappe.parse_json(frappe.local.assets_json)
return frappe.local.assets_json


def get_bench_relative_path(file_path):


正在加载...
取消
保存