perf: cache permission results
For each transition, we end up redoing perm check. Nothing has really changed there though.
This commit is contained in:
parent
b0a4425230
commit
140a01e2cf
1 changed files with 11 additions and 15 deletions
|
|
@ -324,9 +324,19 @@ def get_next_possible_transitions(workflow_name, state, doc=None):
|
|||
|
||||
def get_users_next_action_data(transitions, doc):
|
||||
user_data_map = {}
|
||||
|
||||
@frappe.request_cache
|
||||
def user_has_permission(user: str) -> bool:
|
||||
from frappe.permissions import has_permission
|
||||
|
||||
return has_permission(doctype=doc, user=user, print_logs=False)
|
||||
|
||||
for transition in transitions:
|
||||
users = get_users_with_role(transition.allowed)
|
||||
filtered_users = filter_allowed_users(users, doc, transition)
|
||||
filtered_users = [
|
||||
user for user in users if has_approval_access(user, doc, transition) and user_has_permission(user)
|
||||
]
|
||||
|
||||
for user in filtered_users:
|
||||
if not user_data_map.get(user):
|
||||
user_data_map[user] = frappe._dict(
|
||||
|
|
@ -454,20 +464,6 @@ def get_doc_workflow_state(doc):
|
|||
return doc.get(workflow_state_field)
|
||||
|
||||
|
||||
def filter_allowed_users(users, doc, transition):
|
||||
"""Filters list of users by checking if user has access to doc and
|
||||
if the user satisfies 'workflow transision self approval' condition
|
||||
"""
|
||||
from frappe.permissions import has_permission
|
||||
|
||||
return [
|
||||
user
|
||||
for user in users
|
||||
if has_approval_access(user, doc, transition)
|
||||
and has_permission(doctype=doc, user=user, print_logs=False)
|
||||
]
|
||||
|
||||
|
||||
def get_common_email_args(doc):
|
||||
doctype = doc.get("doctype")
|
||||
docname = doc.get("name")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue