perf: Cache accounting dimension filter map
This commit is contained in:
@@ -38,37 +38,40 @@ class AccountingDimensionFilter(Document):
|
|||||||
|
|
||||||
|
|
||||||
def get_dimension_filter_map():
|
def get_dimension_filter_map():
|
||||||
filters = frappe.db.sql(
|
if not frappe.flags.get("dimension_filter_map"):
|
||||||
"""
|
filters = frappe.db.sql(
|
||||||
SELECT
|
"""
|
||||||
a.applicable_on_account, d.dimension_value, p.accounting_dimension,
|
SELECT
|
||||||
p.allow_or_restrict, a.is_mandatory
|
a.applicable_on_account, d.dimension_value, p.accounting_dimension,
|
||||||
FROM
|
p.allow_or_restrict, a.is_mandatory
|
||||||
`tabApplicable On Account` a, `tabAllowed Dimension` d,
|
FROM
|
||||||
`tabAccounting Dimension Filter` p
|
`tabApplicable On Account` a, `tabAllowed Dimension` d,
|
||||||
WHERE
|
`tabAccounting Dimension Filter` p
|
||||||
p.name = a.parent
|
WHERE
|
||||||
AND p.disabled = 0
|
p.name = a.parent
|
||||||
AND p.name = d.parent
|
AND p.disabled = 0
|
||||||
""",
|
AND p.name = d.parent
|
||||||
as_dict=1,
|
""",
|
||||||
)
|
as_dict=1,
|
||||||
|
|
||||||
dimension_filter_map = {}
|
|
||||||
|
|
||||||
for f in filters:
|
|
||||||
f.fieldname = scrub(f.accounting_dimension)
|
|
||||||
|
|
||||||
build_map(
|
|
||||||
dimension_filter_map,
|
|
||||||
f.fieldname,
|
|
||||||
f.applicable_on_account,
|
|
||||||
f.dimension_value,
|
|
||||||
f.allow_or_restrict,
|
|
||||||
f.is_mandatory,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return dimension_filter_map
|
dimension_filter_map = {}
|
||||||
|
|
||||||
|
for f in filters:
|
||||||
|
f.fieldname = scrub(f.accounting_dimension)
|
||||||
|
|
||||||
|
build_map(
|
||||||
|
dimension_filter_map,
|
||||||
|
f.fieldname,
|
||||||
|
f.applicable_on_account,
|
||||||
|
f.dimension_value,
|
||||||
|
f.allow_or_restrict,
|
||||||
|
f.is_mandatory,
|
||||||
|
)
|
||||||
|
|
||||||
|
frappe.flags.dimension_filter_map = dimension_filter_map
|
||||||
|
|
||||||
|
return frappe.flags.dimension_filter_map
|
||||||
|
|
||||||
|
|
||||||
def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory):
|
def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory):
|
||||||
|
|||||||
Reference in New Issue
Block a user