perf: use estimated rows instead of actual rows (#38830) (cherry picked from commit 9983283f95753e7523cf30cc258df0572f88081d) Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
parent
4626ab5e19
commit
648f275797
@ -4,7 +4,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import cint, flt, getdate
|
||||
from frappe.utils import cint, flt, get_table_name, getdate
|
||||
from frappe.utils.deprecations import deprecated
|
||||
from pypika import functions as fn
|
||||
|
||||
@ -13,11 +13,22 @@ 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."))
|
||||
|
Loading…
x
Reference in New Issue
Block a user