perf: Cache plain link validation for 30 minutes
Very often you're picking same documents again and again, there's no need to validate them. Also, document is JUST selected using search_link, so it's 99% guaranteed to be valid. The real purpose of this function is to provide "fetch from" feature, not link validation like the name suggests. It will get validated server side anyway.
This commit is contained in:
parent
daf4885f0a
commit
1470ad2a66
2 changed files with 15 additions and 6 deletions
|
|
@ -427,7 +427,11 @@ def validate_link(doctype: str, docname: str, fields=None):
|
|||
values.name = frappe.db.get_value(doctype, docname, cache=True)
|
||||
|
||||
fields = frappe.parse_json(fields)
|
||||
if not values.name or not fields:
|
||||
if not values.name:
|
||||
return values
|
||||
|
||||
if not fields:
|
||||
frappe.local.response_headers.set("Cache-Control", "private,max-age=1800,stale-while-revalidate=7200")
|
||||
return values
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -685,11 +685,16 @@ frappe.ui.form.ControlLink = class ControlLink extends frappe.ui.form.ControlDat
|
|||
// to avoid unnecessary request
|
||||
if (value) {
|
||||
return frappe
|
||||
.xcall("frappe.client.validate_link", {
|
||||
doctype: options,
|
||||
docname: value,
|
||||
fields: columns_to_fetch,
|
||||
})
|
||||
.xcall(
|
||||
"frappe.client.validate_link",
|
||||
{
|
||||
doctype: options,
|
||||
docname: value,
|
||||
fields: columns_to_fetch,
|
||||
},
|
||||
"GET",
|
||||
{ cache: !columns_to_fetch.length }
|
||||
)
|
||||
.then((response) => {
|
||||
if (!this.docname || !columns_to_fetch.length) {
|
||||
return response.name;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue