From 15174a97d5f047908cba2ee52c2c54b323522888 Mon Sep 17 00:00:00 2001 From: Julian Helfferich Date: Mon, 12 Aug 2024 14:43:56 +0200 Subject: [PATCH] CPT-127 Make list of attachments accessible again When opening the list of attachments, Odoo wants to display the total number of items in the list. This is displayed in the top right such as "1 - 80 of 2264". In order to display the total number, Odoo fetches all IDs and filters out the ids to which the user does not have access. For the JobRad database with more than 32 million entries this causes either a MemoryError or a timeout. The suggested solution is to skip the filtering. This means the total number of entries will be wrong. The list can still be navigated without any issues. --- odoo/addons/base/models/ir_attachment.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index ed3a037357cc9..32d19fa35d4a7 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -488,14 +488,14 @@ def _search(self, args, offset=0, limit=None, order=None, count=False, access_ri args.insert(0, ('res_field', '=', False)) ids = super(IrAttachment, self)._search(args, offset=offset, limit=limit, order=order, - count=False, access_rights_uid=access_rights_uid) + count=count, access_rights_uid=access_rights_uid) - if self.env.is_superuser(): + if count or self.env.is_superuser(): # rules do not apply for the superuser - return len(ids) if count else ids + return ids if not ids: - return 0 if count else [] + return [] # Work with a set, as list.remove() is prohibitive for large lists of documents # (takes 20+ seconds on a db with 100k docs during search_count()!) @@ -552,7 +552,7 @@ def _search(self, args, offset=0, limit=None, order=None, count=False, access_ri limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)[:limit - len(result)]) - return len(result) if count else list(result) + return list(result) def _read(self, fields): self.check('read')