Skip to content

Commit

Permalink
perf: use LEFT JOIN instead of NOT EXISTS
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Jul 28, 2023
1 parent e36c8ce commit 58d8675
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions erpnext/manufacturing/doctype/bom_update_log/bom_updation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,19 @@ def _all_children_are_processed(parent_bom):
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:
Expand Down

0 comments on commit 58d8675

Please sign in to comment.