From f28ac2a94d66a0551c65bc1bc1588bf0249f42eb Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 21 Aug 2012 15:19:20 +0200 Subject: [PATCH] [FIX] OPW 577963: ir_attachment: speed up ir.attachment search for large databases Frequents calls to list.remove() were being a bottleneck for large document lists (100k+). Using a set make remove() calls much faster. This commit has a corresponding server patch in the core ir.attachment search method. bzr revid: odo@openerp.com-20120821131920-j653hvmff78fxxtr --- addons/document/document.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/document/document.py b/addons/document/document.py index 9ea7f97..a920da6 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -187,6 +187,10 @@ class document_file(osv.osv): if not ids: return 0 if count else [] + # 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()!) + ids = set(ids) + # Filter out documents that are in directories that the user is not allowed to read. # Must use pure SQL to avoid access rules exceptions (we want to remove the records, # not fail), and the records have been filtered in parent's search() anyway. @@ -198,8 +202,8 @@ class document_file(osv.osv): for doc_id, parent_id in doc_pairs: if parent_id in disallowed_parents: ids.remove(doc_id) - return len(ids) if count else ids + return len(ids) if count else list(ids) def copy(self, cr, uid, id, default=None, context=None): if not default: -- 1.7.10.4