From a3e578068e170df41ef95c00026bc2351c9e2c13 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 25 Nov 2014 14:36:56 +0100 Subject: [PATCH] [FIX] website: improve performance for attachment creation website introduces two new stored function fields, which depend on the attachment data The thing is, these two fields are pertinent for website attachments only Therefore, we avoid to read the datas field when the attachment is not a website attachment(when not needed), as this is the most costly field to read --- addons/website/models/website.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index f7f90459b62..2e92968fa30 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -684,12 +684,12 @@ class ir_attachment(osv.osv): result[attach.id] = self.pool['website'].image_url(cr, uid, attach, 'datas') return result def _datas_checksum(self, cr, uid, ids, name, arg, context=None): - return dict( - (attach['id'], self._compute_checksum(attach)) - for attach in self.read( - cr, uid, ids, ['res_model', 'res_id', 'type', 'datas'], - context=context) - ) + result = dict.fromkeys(ids, False) + attachments = self.read(cr, uid, ids, ['type'], context=context) + view_attachment_ids = [attachment['id'] for attachment in attachments if attachment['type'] == 'ir.ui.view'] + for attach in self.read(cr, uid, view_attachment_ids, ['res_model', 'res_id', 'type', 'datas'], context=context): + result[attach['id']] = self._compute_checksum(attach) + return result def _compute_checksum(self, attachment_dict): if attachment_dict.get('res_model') == 'ir.ui.view'\ @@ -705,7 +705,7 @@ class ir_attachment(osv.osv): return result for record in self.browse(cr, uid, ids, context=context): - if not record.datas: continue + if record.type != 'ir.ui.view' or not record.datas: continue try: result[record.id] = openerp.tools.image_resize_image_big(record.datas) except IOError: # apparently the error PIL.Image.open raises