diff --git a/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py b/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py index f19d45b1d37..90a47613a46 100644 --- a/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py +++ b/apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py @@ -7,11 +7,26 @@ @desc: """ import json -from jsonpath_ng import parse +from jsonpath_ng.ext import parse +from common.cache.mem_cache import MemCache from application.flow.i_step_node import NodeResult from application.flow.step_node.variable_splitting_node.i_variable_splitting_node import IVariableSplittingNode +jsonpath_expr_cache = MemCache('parse_path', { + 'TIMEOUT': 3600, # 缓存有效期为 1 小时 + 'OPTIONS': { + 'MAX_ENTRIES': 1000, # 最多缓存 500 个条目 + 'CULL_FREQUENCY': 10, # 达到上限时,删除约 1/10 的缓存 + }, +}) + +def parse_and_cache(path): + jsonpath_expr = jsonpath_expr_cache.get(path) + if not jsonpath_expr: + jsonpath_expr = parse(path) + jsonpath_expr_cache.set(path, jsonpath_expr) + return jsonpath_expr def smart_jsonpath_search(data: dict, path: str): """ @@ -21,7 +36,7 @@ def smart_jsonpath_search(data: dict, path: str): - 多个匹配: 返回值的列表 - 无匹配: 返回None """ - jsonpath_expr = parse(path) + jsonpath_expr = parse_and_cache(path) matches = jsonpath_expr.find(data) if not matches: diff --git a/pyproject.toml b/pyproject.toml index 4bb07772be0..64cb650f705 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ dependencies = [ "websockets==15.0.1", "pylint==3.3.7", "cohere==5.17.0", - "jsonpath-ng==1.7.0", + "jsonpath-ng==1.8.0", ] [tool.uv] diff --git a/ui/src/locales/lang/en-US/workflow.ts b/ui/src/locales/lang/en-US/workflow.ts index 74fa49f04b4..d4268a6f242 100644 --- a/ui/src/locales/lang/en-US/workflow.ts +++ b/ui/src/locales/lang/en-US/workflow.ts @@ -507,7 +507,7 @@ You are a master of problem optimization, adept at accurately inferring user int expression: { label: 'Expression', placeholder: 'Please enter expression', - tooltip: 'Please use JSON Path expressions to split variables, e.g.: $.store.book', + tooltip: 'Please use JSON Path expressions to split variables, e.g.: $.store.book Click for details ➜ pypi.org', }, }, parameterExtractionNode: { diff --git a/ui/src/locales/lang/zh-CN/workflow.ts b/ui/src/locales/lang/zh-CN/workflow.ts index 0f069ddeccd..cdb243d9d6a 100644 --- a/ui/src/locales/lang/zh-CN/workflow.ts +++ b/ui/src/locales/lang/zh-CN/workflow.ts @@ -498,7 +498,7 @@ export default { expression: { label: '表达式', placeholder: '请输入表达式', - tooltip: '请使用JSON Path 表达式拆分变量,例如:$.store.book', + tooltip: '请使用 JSON Path 表达式拆分变量,例如:$.store.book 点击查看详情 ➜ pypi.org', }, }, parameterExtractionNode: { diff --git a/ui/src/locales/lang/zh-Hant/workflow.ts b/ui/src/locales/lang/zh-Hant/workflow.ts index 25d844d783f..51ceadff86a 100644 --- a/ui/src/locales/lang/zh-Hant/workflow.ts +++ b/ui/src/locales/lang/zh-Hant/workflow.ts @@ -492,7 +492,7 @@ export default { expression: { label: '表達式', placeholder: '請輸入表達式', - tooltip: '請使用 JSON Path 表達式拆分變量,例如:$.store.book', + tooltip: '請使用 JSON Path 表達式拆分變量,例如:$.store.book 點擊查看詳情 ➜ pypi.org', }, }, parameterExtractionNode: { diff --git a/ui/src/workflow/nodes/variable-splitting/component/VariableFieldDialog.vue b/ui/src/workflow/nodes/variable-splitting/component/VariableFieldDialog.vue index 23af2555f7f..71834519fee 100644 --- a/ui/src/workflow/nodes/variable-splitting/component/VariableFieldDialog.vue +++ b/ui/src/workflow/nodes/variable-splitting/component/VariableFieldDialog.vue @@ -57,11 +57,11 @@ > + @@ -161,4 +161,12 @@ const submit = async (formEl: FormInstance | undefined) => { defineExpose({ open, close }) - +