Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: reduce DB calls in frappe.client.get (and other changes) #17665

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 5 additions & 12 deletions frappe/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,9 @@ def get(doctype, name=None, filters=None, parent=None):
if frappe.is_table(doctype):
check_parent_permission(parent, doctype)

if filters and not name:
name = frappe.db.get_value(doctype, frappe.parse_json(filters))
if not name:
frappe.throw(_("No document found for given filters"))

doc = frappe.get_doc(doctype, name)
if not doc.has_permission("read"):
raise frappe.PermissionError

return frappe.get_doc(doctype, name).as_dict()
doc = frappe.get_doc(doctype, name or frappe.parse_json(filters))
doc.check_permission()
return doc.as_dict()


@frappe.whitelist()
Expand Down Expand Up @@ -144,8 +137,8 @@ def get_value(doctype, fieldname, filters=None, as_dict=True, debug=False, paren
def get_single_value(doctype, field):
if not frappe.has_permission(doctype):
frappe.throw(_("No permission for {0}").format(_(doctype)), frappe.PermissionError)
value = frappe.db.get_single_value(doctype, field)
return value

return frappe.db.get_single_value(doctype, field)


@frappe.whitelist(methods=["POST", "PUT"])
Expand Down