Cached some queries (#5951)

This commit is contained in:
Nabin Hait 2018-08-09 11:25:07 +05:30 committed by Rushabh Mehta
parent b1857a5132
commit 39e9e306f2
2 changed files with 8 additions and 7 deletions

View file

@ -46,7 +46,7 @@ class Address(Document):
if not self.links and not self.is_your_company_address:
contact_name = frappe.db.get_value("Contact", {"email_id": self.owner})
if contact_name:
contact = frappe.get_doc('Contact', contact_name)
contact = frappe.get_cached_doc('Contact', contact_name)
for link in contact.links:
self.append('links', dict(link_doctype=link.link_doctype, link_name=link.link_name))
return True
@ -104,7 +104,7 @@ def get_address_display(address_dict):
return
if not isinstance(address_dict, dict):
address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True) or {}
address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True, cache=True) or {}
name, template = get_address_templates(address_dict)
@ -120,13 +120,14 @@ def get_territory_from_address(address):
return
if isinstance(address, string_types):
address = frappe.get_doc("Address", address)
address = frappe.get_cached_doc("Address", address)
territory = None
for fieldname in ("city", "state", "country"):
territory = frappe.db.get_value("Territory", address.get(fieldname))
if territory:
break
if address.get(fieldname):
territory = frappe.db.get_value("Territory", address.get(fieldname))
if territory:
break
return territory

View file

@ -481,7 +481,7 @@ def get_field_currency(df, doc=None):
if ":" in cstr(df.get("options")):
split_opts = df.get("options").split(":")
if len(split_opts)==3:
currency = frappe.db.get_value(split_opts[0], doc.get(split_opts[1]), split_opts[2])
currency = frappe.get_cached_value(split_opts[0], doc.get(split_opts[1]), split_opts[2])
else:
currency = doc.get(df.get("options"))
if doc.parent: