perf: Ignore amended_from link fields in link field checks

Small perf benefit at not much cost. `amended_from` are *always*
refererring to cancelled documents so there's no need to check these
fields.
This commit is contained in:
Ankush Menat 2023-10-31 14:33:15 +05:30
parent 8d7eac3cb0
commit 6926669577
2 changed files with 8 additions and 2 deletions

View file

@ -71,7 +71,7 @@ class SubmittableDocumentTree:
def get_all_children(self):
"""Get all nodes of a tree except the root node (all the nested submitted
documents those are present in referencing tables (dependent tables).
documents those are present in referencing tables dependent tables).
"""
while self.to_be_visited_documents:
next_level_children = defaultdict(list)
@ -101,6 +101,10 @@ class SubmittableDocumentTree:
child_docs = defaultdict(list)
for field in referencing_fields:
if field["fieldname"] == "amended_from":
# perf: amended_from links are always linked to cancelled documents.
continue
links = (
get_referencing_documents(
parent_dt,

View file

@ -249,6 +249,8 @@ def check_if_doc_is_linked(doc, method="Delete"):
for lf in link_fields:
link_dt, link_field, issingle = lf["parent"], lf["fieldname"], lf["issingle"]
if link_field == "amended_from":
continue
try:
meta = frappe.get_meta(link_dt)
@ -258,7 +260,7 @@ def check_if_doc_is_linked(doc, method="Delete"):
continue
if issingle:
if frappe.db.get_value(link_dt, None, link_field) == doc.name:
if frappe.db.get_single_value(link_dt, link_field) == doc.name:
raise_link_exists_exception(doc, link_dt, link_dt)
continue