perf: Task import with Project (#17496)
When tasks are imported with their Project set, import slows down as
number of tasks increase. This is largely due to `load_tasks` being
called in Project which is only required when Form loads. So, we can
skip it during import.
Also, converted some get_doc calls to get_cached_doc.
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 39222ac..61db3e1 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -35,6 +35,9 @@
def load_tasks(self):
"""Load `tasks` from the database"""
+ if frappe.flags.in_import:
+ return
+
self.tasks = []
for task in self.get_tasks():
task_map = {
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 84ee715..fa9a5a5 100755
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -105,7 +105,7 @@
def update_project(self):
if self.project and not self.flags.from_project:
- frappe.get_doc("Project", self.project).update_project()
+ frappe.get_cached_doc("Project", self.project).update_project()
def check_recursion(self):
if self.flags.ignore_recursion_check: return
@@ -150,7 +150,7 @@
def populate_depends_on(self):
if self.parent_task:
- parent = frappe.get_doc('Task', self.parent_task)
+ parent = frappe.get_cached_doc('Task', self.parent_task)
if not self.name in [row.task for row in parent.depends_on]:
parent.append("depends_on", {
"doctype": "Task Depends On",