Skip to content

Commit

Permalink
perf: reduce DB call in frappe.client.get (#17665)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarvora committed Aug 2, 2022
1 parent 2d1fe02 commit ebb0cd1
Showing 1 changed file with 5 additions and 12 deletions.
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

0 comments on commit ebb0cd1

Please sign in to comment.