From e2cec54fad2b205590d4a3cf19fb258058492a68 Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Fri, 10 Feb 2023 20:42:01 +0000 Subject: [PATCH] [FIX] project: improve performance for burndown chart report Before this commit when the user wants to see the burndown chart of a old large project then the report could take more than 20 sec to be loaded. This commit adds 2 indexes one on `mail_tracking_value` table (`mail.tracking.value` model) and the other one on `mail_message` table (`mail.message` model) to reduce the load of that report to less than 10 sec. task-3177072 closes odoo/odoo#114114 X-original-commit: c6b355d471889634ae26a020e14c81e9a315b3de Signed-off-by: Xavier Bol (xbo) Co-authored-by: Yannick Tivisse --- addons/project/__init__.py | 12 ++++++++++++ addons/project/models/__init__.py | 1 + addons/project/models/mail_message.py | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 addons/project/models/mail_message.py diff --git a/addons/project/__init__.py b/addons/project/__init__.py index a983dc5d67a..e5493f8675a 100644 --- a/addons/project/__init__.py +++ b/addons/project/__init__.py @@ -7,6 +7,8 @@ from . import report from . import wizard from . import populate +from odoo.tools.sql import create_index + def _check_exists_collaborators_for_project_sharing(env): """ Check if it exists at least a collaborator in a shared project @@ -21,3 +23,13 @@ def _check_exists_collaborators_for_project_sharing(env): def _project_post_init(env): _check_exists_collaborators_for_project_sharing(env) + + # Index to improve the performance of burndown chart. + project_task_stage_field_id = env['ir.model.fields']._get_ids('project.task').get('stage_id') + create_index( + env.cr, + 'mail_tracking_value_mail_message_id_old_value_integer_task_stage', + env['mail.tracking.value']._table, + ['mail_message_id', 'old_value_integer'], + where=f'field={project_task_stage_field_id}' + ) diff --git a/addons/project/models/__init__.py b/addons/project/models/__init__.py index 3f3151245a2..1a600154490 100644 --- a/addons/project/models/__init__.py +++ b/addons/project/models/__init__.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import analytic_account +from . import mail_message from . import project_milestone from . import project_project_stage from . import project_task_recurrence diff --git a/addons/project/models/mail_message.py b/addons/project/models/mail_message.py new file mode 100644 index 00000000000..009564854f3 --- /dev/null +++ b/addons/project/models/mail_message.py @@ -0,0 +1,18 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models +from odoo.tools.sql import create_index + + +class MailMessage(models.Model): + _inherit = 'mail.message' + + def init(self): + super().init() + create_index( + self._cr, + 'mail_message_date_res_id_id_for_burndown_chart', + self._table, + ['date', 'res_id', 'id'], + where="model='project.task' AND message_type='notification'" + )