Compare commits

...

5 Commits

Author SHA1 Message Date
Ankush Menat
401f276334 perf: Drop cost center index
This was only added to allow renaming for one user (?) can be added if
there's a more serious use case than that.
2025-04-21 22:40:30 +05:30
Ankush Menat
f25524ff95 perf: Drop paty_type + party index
party alone provides almost all of cardinality.

party_type might be separately useful in some cases but I don't see
anything here.
2025-04-21 22:40:30 +05:30
Ankush Menat
34896f1cd1 perf: remove voucher_type + voucher_no index
Voucher_no is real source of cardinality here... voucher_type will just
be 10-20 unique types, not really helping much here.
2025-04-21 22:40:30 +05:30
Ankush Menat
4cbc92649f perf: Only created company indexes in multi-company setups
A vast vast majority of installations don't have multiple companies, so
this unnecessary index is an overhead for them.
2025-04-21 22:40:30 +05:30
Ankush Menat
1b85fbf0e5 perf: Drop party_type index
It's covered by party_type + party index. So this is not required at all.

Party type is also a rarely used as most selective filter => By nature it has very low cardinality.
2025-04-21 22:40:27 +05:30
3 changed files with 19 additions and 11 deletions

View File

@@ -86,8 +86,7 @@
"fieldname": "party_type",
"fieldtype": "Link",
"label": "Party Type",
"options": "DocType",
"search_index": 1
"options": "DocType"
},
{
"fieldname": "party",
@@ -105,8 +104,7 @@
"label": "Cost Center",
"oldfieldname": "cost_center",
"oldfieldtype": "Link",
"options": "Cost Center",
"search_index": 1
"options": "Cost Center"
},
{
"fieldname": "debit",
@@ -243,8 +241,7 @@
"label": "Company",
"oldfieldname": "company",
"oldfieldtype": "Link",
"options": "Company",
"search_index": 1
"options": "Company"
},
{
"fieldname": "finance_book",
@@ -359,7 +356,7 @@
"idx": 1,
"in_create": 1,
"links": [],
"modified": "2025-03-21 15:29:11.221890",
"modified": "2025-04-21 22:37:16.349564",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
@@ -390,8 +387,9 @@
}
],
"quick_entry": 1,
"row_format": "Dynamic",
"search_fields": "voucher_no,account,posting_date,against_voucher",
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
}

View File

@@ -438,9 +438,14 @@ def update_against_account(voucher_type, voucher_no):
def on_doctype_update():
frappe.db.add_index("GL Entry", ["voucher_type", "voucher_no"])
frappe.db.add_index("GL Entry", ["posting_date", "company"])
frappe.db.add_index("GL Entry", ["party_type", "party"])
add_company_indexes()
def add_company_indexes():
"""Only add company indexes if more than one company exists."""
if frappe.db.count("Company", {"name": ("not like", "%(Demo)%")}) > 1:
frappe.db.add_index("GL Entry", ["posting_date", "company"])
frappe.db.add_index("GL Entry", ["company"])
def rename_gle_sle_docs():

View File

@@ -707,6 +707,11 @@ class Company(NestedSet):
):
frappe.flags.parent_company_changed = True
def before_insert(self):
from erpnext.accounts.doctype.gl_entry.gl_entry import add_company_indexes
add_company_indexes()
def get_name_with_abbr(name, company):
company_abbr = frappe.get_cached_value("Company", company, "abbr")