Added indexes for lft, rgt on nestedset doctypes (#13420)

This commit is contained in:
Nabin Hait 2018-04-02 10:43:46 +05:30 committed by GitHub
parent 5d71609f0b
commit c825e914d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 37 additions and 3 deletions

View File

@ -273,4 +273,8 @@ def update_account_number(name, account_number):
def get_name_with_number(new_account, account_number):
if account_number and not new_account[0].isdigit():
new_account = account_number + " - " + new_account
return new_account
return new_account
def on_doctype_update():
frappe.db.add_index("Account", ["lft", "rgt"])

View File

@ -64,3 +64,6 @@ class CostCenter(NestedSet):
if not merge:
frappe.db.set_value("Cost Center", newdn, "cost_center_name",
" - ".join(newdn.split(" - ")[:-1]))
def on_doctype_update():
frappe.db.add_index("Cost Center", ["lft", "rgt"])

View File

@ -177,4 +177,7 @@ def get_children(doctype, parent, is_root=False):
# return nodes
return land_units
def on_doctype_update():
frappe.db.add_index("Land Unit", ["lft", "rgt"])

View File

@ -329,4 +329,8 @@ def get_children(doctype, parent=None, company=None, is_root=False, is_tree=Fals
.format(company=company, condition=condition), as_dict=1)
# return employee
return employee
return employee
def on_doctype_update():
frappe.db.add_index("Employee", ["lft", "rgt"])

View File

@ -515,3 +515,4 @@ erpnext.patches.v10_0.update_hub_connector_domain
erpnext.patches.v10_0.set_student_party_type
erpnext.patches.v10_0.update_project_in_sle
erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract
erpnext.patches.v11_0.add_index_on_nestedset_doctypes

View File

@ -0,0 +1,8 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
def execute():
for dt in ("Account", "Cost Center", "File", "Employee", "Land Unit", "Task", "Customer Group", "Sales Person", "Territory"):
frappe.get_doc("DocType", dt).run_module_method("on_doctype_update")

View File

@ -236,3 +236,6 @@ def add_multiple_tasks(data, parent):
new_doc['subject'] = d.get("subject")
new_task = frappe.get_doc(new_doc)
new_task.insert()
def on_doctype_update():
frappe.db.add_index("Task", ["lft", "rgt"])

View File

@ -25,3 +25,6 @@ def get_parent_customer_groups(customer_group):
return frappe.db.sql("""select name from `tabCustomer Group`
where lft <= %s and rgt >= %s
order by lft asc""", (lft, rgt), as_dict=True)
def on_doctype_update():
frappe.db.add_index("Customer Group", ["lft", "rgt"])

View File

@ -33,3 +33,6 @@ class SalesPerson(NestedSet):
if sales_person and sales_person != self.name:
frappe.throw(_("Another Sales Person {0} exists with the same Employee id").format(sales_person))
def on_doctype_update():
frappe.db.add_index("Sales Person", ["lft", "rgt"])

View File

@ -22,3 +22,5 @@ class Territory(NestedSet):
super(Territory, self).on_update()
self.validate_one_root()
def on_doctype_update():
frappe.db.add_index("Territory", ["lft", "rgt"])