perf: Simplify dynamic route evaluation to speed up route resolution
validate complete route only if starting of the path matches with the webform route This avoids the expensive matching from huge route_map (in sites with lots of web forms)
This commit is contained in:
parent
7452e71d02
commit
bc2b41d2f5
2 changed files with 16 additions and 14 deletions
|
|
@ -279,7 +279,7 @@ def get_context(context):
|
|||
if field.fieldtype == "Select" and field.options:
|
||||
messages.extend(field.options.split("\n"))
|
||||
|
||||
messages.extend(col.label for col in self.list_columns)
|
||||
messages.extend(col.get("label") if col else "" for col in self.list_columns)
|
||||
|
||||
context.translated_messages = frappe.as_json(
|
||||
{message: _(message) for message in messages if message}
|
||||
|
|
|
|||
|
|
@ -34,27 +34,29 @@ def get_page_info_from_web_form(path):
|
|||
"""Query published web forms and evaluate if the route matches"""
|
||||
from frappe.website.doctype.web_form.web_form import get_published_web_forms
|
||||
|
||||
rules, page_info = [], {}
|
||||
for d in get_published_web_forms():
|
||||
if not (path.startswith(f"{d.route}") or path.startswith(f"/{d.route}")):
|
||||
continue
|
||||
|
||||
rules = []
|
||||
rules.append(Rule(f"/{d.route}", endpoint=d.name))
|
||||
rules.append(Rule(f"/{d.route}/list", endpoint=d.name))
|
||||
rules.append(Rule(f"/{d.route}/new", endpoint=d.name))
|
||||
rules.append(Rule(f"/{d.route}/<name>", endpoint=d.name))
|
||||
rules.append(Rule(f"/{d.route}/<name>/edit", endpoint=d.name))
|
||||
d.doctype = "Web Form"
|
||||
page_info[d.name] = d
|
||||
end_point = evaluate_dynamic_routes(rules, path)
|
||||
|
||||
end_point = evaluate_dynamic_routes(rules, path)
|
||||
if end_point:
|
||||
if path.endswith("/list"):
|
||||
frappe.form_dict.is_list = True
|
||||
elif path.endswith("/new"):
|
||||
frappe.form_dict.is_new = True
|
||||
elif path.endswith("/edit"):
|
||||
frappe.form_dict.is_edit = True
|
||||
else:
|
||||
frappe.form_dict.is_read = True
|
||||
return page_info[end_point]
|
||||
if end_point:
|
||||
if path.endswith("/list"):
|
||||
frappe.form_dict.is_list = True
|
||||
elif path.endswith("/new"):
|
||||
frappe.form_dict.is_new = True
|
||||
elif path.endswith("/edit"):
|
||||
frappe.form_dict.is_edit = True
|
||||
else:
|
||||
frappe.form_dict.is_read = True
|
||||
return d
|
||||
|
||||
|
||||
def evaluate_dynamic_routes(rules, path):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue