Files
odoo_source/addons/project/__init__.py
T
Xavier BOL (xbo)andYannick Tivisse e2cec54fad [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) <xbo@odoo.com>
Co-authored-by: Yannick Tivisse <yti@odoo.com>
2023-03-07 23:09:58 +01:00

36 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
from . import models
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
If it is the case we need to active the portal rules added only for this feature.
"""
collaborator = env['project.collaborator'].search([], limit=1)
if collaborator:
# Then we need to enable the access rights linked to project sharing for the portal user
env['project.collaborator']._toggle_project_sharing_portal_rules(True)
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}'
)