From 84acba23a807f2ab7cd0ad65b4ac79878915150a Mon Sep 17 00:00:00 2001 From: Celina Devigili Date: Fri, 2 Oct 2026 20:10:54 +0000 Subject: [PATCH] [IMP] project_ux: index followers of tasks by partner Add a partial index on mail_followers (partner_id, res_id) for project.task rows. The project.task record rules check if the user follows the task, and with many followed tasks per user that subquery is most of the cost of task counts and searches. --- project_ux/models/__init__.py | 1 + project_ux/models/mail_followers.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 project_ux/models/mail_followers.py diff --git a/project_ux/models/__init__.py b/project_ux/models/__init__.py index c6141a05..e3af6818 100644 --- a/project_ux/models/__init__.py +++ b/project_ux/models/__init__.py @@ -5,3 +5,4 @@ ############################################################################## from . import project_task_type from . import project_task +from . import mail_followers diff --git a/project_ux/models/mail_followers.py b/project_ux/models/mail_followers.py new file mode 100644 index 00000000..2abb69c4 --- /dev/null +++ b/project_ux/models/mail_followers.py @@ -0,0 +1,16 @@ +from odoo import models +from odoo.tools.sql import create_index + + +class MailFollowers(models.Model): + _inherit = "mail.followers" + + def init(self): + super().init() + create_index( # used by the project.task record rules on followers + self.env.cr, + indexname="mail_followers_project_task_partner_id_res_id_index", + tablename=self._table, + expressions=["partner_id", "res_id"], + where="res_model = 'project.task'", + )