Skip to content

Commit

Permalink
perf: use estimated rows instead of actual rows (#38830)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9983283)

# Conflicts:
#	erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py
  • Loading branch information
ankush authored and mergify[bot] committed Dec 20, 2023
1 parent d94b5a3 commit 10a5e95
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@

import frappe
from frappe import _
<<<<<<< HEAD
from frappe.utils import cint, flt, getdate
=======
from frappe.utils import cint, flt, get_table_name, getdate
from frappe.utils.deprecations import deprecated
>>>>>>> 9983283f95 (perf: use estimated rows instead of actual rows (#38830))
from pypika import functions as fn

from erpnext.stock.doctype.warehouse.warehouse import apply_warehouse_filter

SLE_COUNT_LIMIT = 10_000


def _estimate_table_row_count(doctype: str):
table = get_table_name(doctype)
return cint(
frappe.db.sql(
f"""select table_rows
from information_schema.tables
where table_name = '{table}' ;"""
)[0][0]
)


def execute(filters=None):
if not filters:
filters = {}

sle_count = frappe.db.count("Stock Ledger Entry")
sle_count = _estimate_table_row_count("Stock Ledger Entry")

if sle_count > SLE_COUNT_LIMIT and not filters.get("item_code") and not filters.get("warehouse"):
frappe.throw(_("Please select either the Item or Warehouse filter to generate the report."))
Expand Down

0 comments on commit 10a5e95

Please sign in to comment.