Merge pull request #32836 from resilient-tech/perf-fix-get-cached-value-for-accounts

perf: use `get_cached_value` instead of `db.get_value` in accounts module
This commit is contained in:
Deepesh Garg
2022-11-23 18:20:48 +05:30
committed by GitHub
33 changed files with 130 additions and 120 deletions

View File

@@ -174,7 +174,7 @@ def get_gl_entries(filters, accounting_dimensions):
order_by_statement = "order by account, posting_date, creation"
if filters.get("include_default_book_entries"):
filters["company_fb"] = frappe.db.get_value(
filters["company_fb"] = frappe.get_cached_value(
"Company", filters.get("company"), "default_finance_book"
)
@@ -286,9 +286,11 @@ def get_accounts_with_children(accounts):
all_accounts = []
for d in accounts:
if frappe.db.exists("Account", d):
lft, rgt = frappe.db.get_value("Account", d, ["lft", "rgt"])
children = frappe.get_all("Account", filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
account = frappe.get_cached_doc("Account", d)
if account:
children = frappe.get_all(
"Account", filters={"lft": [">=", account.lft], "rgt": ["<=", account.rgt]}
)
all_accounts += [c.name for c in children]
else:
frappe.throw(_("Account: {0} does not exist").format(d))