From dcb95aac0707cc66902117a7624f0feee7126dda Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Wed, 13 Aug 2025 01:33:24 +0000 Subject: [PATCH] [FIX] mail_message_search : prevent db crash Co-authored-by: Florent de Labarre --- mail_message_search/README.rst | 24 ++++++--- mail_message_search/models/mail_thread.py | 10 +++- mail_message_search/readme/CONFIGURE.md | 7 +++ .../static/description/index.html | 54 +++++++++++-------- 4 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 mail_message_search/readme/CONFIGURE.md diff --git a/mail_message_search/README.rst b/mail_message_search/README.rst index 5d2d36c3f..627b3e01c 100644 --- a/mail_message_search/README.rst +++ b/mail_message_search/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - =================== Mail Message Search =================== @@ -17,7 +13,7 @@ Mail Message Search .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github @@ -61,6 +57,18 @@ This module uses direct keyword matching across key fields in ``mail.message``, offering more reliable results in multilingual environments. +Configuration +============= + +If your database is very large, you can limit how many messages a search +returns to prevent crashes. + +- Go to Settings ▸ Technical ▸ System Parameters. +- Add a new parameter: + + - Key: mail_message_search.message_limit + - Value: your desired limit (e.g., 5000). + Usage ===== @@ -88,10 +96,10 @@ Authors Contributors ------------ -- `Quartile `__: +- `Quartile `__: - - Aung Ko Ko Lin - - Yoshi Tashiro + - Aung Ko Ko Lin + - Yoshi Tashiro Maintainers ----------- diff --git a/mail_message_search/models/mail_thread.py b/mail_message_search/models/mail_thread.py index 4ce3d3a3b..4789283e3 100644 --- a/mail_message_search/models/mail_thread.py +++ b/mail_message_search/models/mail_thread.py @@ -26,8 +26,14 @@ def _search_message_search(self, operator, value): word_domain_list.append(expression.OR(field_domain_list)) word_domain = expression.AND(word_domain_list) domain = expression.AND([[("model", "=", self._name)], word_domain]) - messages = self.env["mail.message"].search(domain) - return [("id", "in", messages.mapped("res_id"))] + limit_value = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("mail_message_search.message_limit") + ) + limit = int(limit_value) if limit_value else None + messages = self.env["mail.message"]._search(domain, limit=limit) + return [("id", "in", messages.subselect("res_id"))] message_search = fields.Text( help="Message search, to be used only in searches", diff --git a/mail_message_search/readme/CONFIGURE.md b/mail_message_search/readme/CONFIGURE.md new file mode 100644 index 000000000..3bace50dc --- /dev/null +++ b/mail_message_search/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +If your database is very large, you can limit how many messages a search returns to +prevent crashes. + +- Go to Settings ▸ Technical ▸ System Parameters. +- Add a new parameter: + - Key: mail_message_search.message_limit + - Value: your desired limit (e.g., 5000). diff --git a/mail_message_search/static/description/index.html b/mail_message_search/static/description/index.html index e12043477..fe8e64426 100644 --- a/mail_message_search/static/description/index.html +++ b/mail_message_search/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Mail Message Search -
+