perf: get ancestors only if needed
This commit is contained in:
parent
86fcea4578
commit
ceb4ee8bf2
1 changed files with 9 additions and 4 deletions
|
|
@ -366,11 +366,8 @@ def has_user_permission(doc, user=None, debug=False, *, ptype=None):
|
|||
not_permitted = True
|
||||
if doc.meta.is_tree and ptype == "create":
|
||||
if parent := doc.get(doc.nsm_parent_field):
|
||||
from frappe.utils.nestedset import get_ancestors_of
|
||||
|
||||
doc_hide_descendants = {d.doc: d.hide_descendants for d in doctype_up}
|
||||
|
||||
for d in [parent, *get_ancestors_of(doctype, parent)]:
|
||||
for d in _get_parent_and_ancestors(doctype, parent):
|
||||
if d in allowed_docs and not doc_hide_descendants[d]:
|
||||
not_permitted = False
|
||||
break
|
||||
|
|
@ -895,3 +892,11 @@ def handle_does_not_exist_error(fn):
|
|||
return fn(e, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def _get_parent_and_ancestors(doctype, parent):
|
||||
yield parent
|
||||
|
||||
from frappe.utils.nestedset import get_ancestors_of
|
||||
|
||||
yield from get_ancestors_of(doctype, parent)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue