perf: cache "is_document_amended"

A document that is amended from something stays amended.
This commit is contained in:
Ankush Menat 2025-01-24 16:48:12 +05:30
parent 153c38571f
commit 5cf5f66fec
2 changed files with 11 additions and 4 deletions

View file

@ -12,6 +12,7 @@ from frappe.desk.reportview import validate_args
from frappe.model.db_query import check_parent_permission
from frappe.model.utils import is_virtual_doctype
from frappe.utils import get_safe_filters
from frappe.utils.caching import http_cache
if TYPE_CHECKING:
from frappe.model.document import Document
@ -385,6 +386,7 @@ def attach_file(
@frappe.whitelist()
@http_cache(max_age=10 * 60)
def is_document_amended(doctype, docname):
if frappe.permissions.has_permission(doctype):
try:

View file

@ -660,10 +660,15 @@ frappe.ui.form.Toolbar = class Toolbar {
if (status !== this.current_status && status === "Amend") {
let doc = this.frm.doc;
frappe
.xcall("frappe.client.is_document_amended", {
doctype: doc.doctype,
docname: doc.name,
})
.xcall(
"frappe.client.is_document_amended",
{
doctype: doc.doctype,
docname: doc.name,
},
"GET",
{ cache: true }
)
.then((is_amended) => {
if (is_amended) {
this.page.clear_actions();