[IMP] project: add 3 indexes to project_task
This commit adds 3 indexes targeting project_task which are not only useful in regular RW use cases, but help tremendously when deleting tasks. In a production scenario, deleting a single task record went from 685ms to 5ms. Equivalent queries for an existing database: CREATE INDEX account_analytic_line_task_id_index ON account_analytic_line(task_id); CREATE INDEX project_task_parent_id_index ON project_task(parent_id); CREATE INDEX sale_order_line_task_id_index ON sale_order_line(task_id);
This commit is contained in:
@@ -14,7 +14,7 @@ class AccountAnalyticLine(models.Model):
|
||||
result['employee_id'] = self.env['hr.employee'].search([('user_id', '=', result['user_id'])], limit=1).id
|
||||
return result
|
||||
|
||||
task_id = fields.Many2one('project.task', 'Task')
|
||||
task_id = fields.Many2one('project.task', 'Task', index=True)
|
||||
project_id = fields.Many2one('project.project', 'Project', domain=[('allow_timesheets', '=', True)])
|
||||
|
||||
employee_id = fields.Many2one('hr.employee', "Employee")
|
||||
|
||||
@@ -455,7 +455,7 @@ class Task(models.Model):
|
||||
legend_blocked = fields.Char(related='stage_id.legend_blocked', string='Kanban Blocked Explanation', readonly=True, related_sudo=False)
|
||||
legend_done = fields.Char(related='stage_id.legend_done', string='Kanban Valid Explanation', readonly=True, related_sudo=False)
|
||||
legend_normal = fields.Char(related='stage_id.legend_normal', string='Kanban Ongoing Explanation', readonly=True, related_sudo=False)
|
||||
parent_id = fields.Many2one('project.task', string='Parent Task')
|
||||
parent_id = fields.Many2one('project.task', string='Parent Task', index=True)
|
||||
child_ids = fields.One2many('project.task', 'parent_id', string="Sub-tasks")
|
||||
subtask_project_id = fields.Many2one('project.project', related="project_id.subtask_project_id", string='Sub-task Project', readonly=True)
|
||||
subtask_count = fields.Integer(compute='_compute_subtask_count', type='integer', string="Sub-task count")
|
||||
|
||||
@@ -136,7 +136,7 @@ class SaleOrder(models.Model):
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
task_id = fields.Many2one('project.task', 'Task', help="Task generated by the sales order item")
|
||||
task_id = fields.Many2one('project.task', 'Task', index=True, help="Task generated by the sales order item")
|
||||
is_service = fields.Boolean("Is a Service", compute='_compute_is_service', store=True, help="Sales Order item should generate a task and/or a project, depending on the product settings.")
|
||||
|
||||
@api.multi
|
||||
|
||||
Reference in New Issue
Block a user