From 58d867503b38fb72c850a2008ec5f33455e643d0 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Fri, 28 Jul 2023 15:53:54 +0530 Subject: [PATCH 1/2] perf: use `LEFT JOIN` instead of `NOT EXISTS` --- .../bom_update_log/bom_updation_utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom_update_log/bom_updation_utils.py b/erpnext/manufacturing/doctype/bom_update_log/bom_updation_utils.py index b90cfd942f..a2919b79b8 100644 --- a/erpnext/manufacturing/doctype/bom_update_log/bom_updation_utils.py +++ b/erpnext/manufacturing/doctype/bom_update_log/bom_updation_utils.py @@ -157,12 +157,19 @@ def get_next_higher_level_boms( def get_leaf_boms() -> List[str]: "Get BOMs that have no dependencies." - return frappe.db.sql_list( - """select name from `tabBOM` bom - where docstatus=1 and is_active=1 - and not exists(select bom_no from `tabBOM Item` - where parent=bom.name and bom_no !='')""" - ) + bom = frappe.qb.DocType("BOM") + bom_item = frappe.qb.DocType("BOM Item") + + boms = ( + frappe.qb.from_(bom) + .left_join(bom_item) + .on((bom.name == bom_item.parent) & (bom_item.bom_no != "")) + .select(bom.name) + .where((bom.docstatus == 1) & (bom.is_active == 1) & (bom_item.bom_no.isnull())) + .distinct() + ).run(pluck=True) + + return boms def _generate_dependence_map() -> defaultdict: From 148d466ae53b4754b5ea7209d9d67f6731f6a2d3 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Fri, 28 Jul 2023 17:05:17 +0530 Subject: [PATCH 2/2] fix: long queue `process_boms_cost_level_wise` --- erpnext/manufacturing/doctype/bom_update_log/bom_update_log.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.py b/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.py index 17b5aae966..e9867468f9 100644 --- a/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.py +++ b/erpnext/manufacturing/doctype/bom_update_log/bom_update_log.py @@ -93,6 +93,7 @@ class BOMUpdateLog(Document): else: frappe.enqueue( method="erpnext.manufacturing.doctype.bom_update_log.bom_update_log.process_boms_cost_level_wise", + queue="long", update_doc=self, now=frappe.flags.in_test, enqueue_after_commit=True,