[FIX] base: perf - binary_record, don't rebrowse ir.attachment
If model is already an ir.attachment we don't need to do a new search_read. We can use it record directly. After this commit, we don't do extra request if we already have the info, else we don't change the behavior. task-2211013
This commit is contained in:
committed by
Romain Derie
parent
6d6b505598
commit
1606d22d40
@@ -119,4 +119,4 @@ class TestWebsitePerformance(UtilPerf):
|
||||
# assets route /web/content/..
|
||||
self.url_open('/') # create assets attachments
|
||||
assets_url = self.env['ir.attachment'].search([('url', '=like', '/web/content/%/web.assets_common%.js')], limit=1).url
|
||||
self.assertEqual(self._get_url_hot_query(assets_url), 3)
|
||||
self.assertEqual(self._get_url_hot_query(assets_url), 2)
|
||||
|
||||
@@ -370,11 +370,16 @@ class IrHttp(models.AbstractModel):
|
||||
|
||||
field_def = record._fields[field]
|
||||
if field_def.type == 'binary' and field_def.attachment:
|
||||
field_attachment = self.env['ir.attachment'].sudo().search_read(domain=[('res_model', '=', model), ('res_id', '=', record.id), ('res_field', '=', field)], fields=['datas', 'mimetype', 'checksum'], limit=1)
|
||||
if field_attachment:
|
||||
mimetype = field_attachment[0]['mimetype']
|
||||
content = field_attachment[0]['datas']
|
||||
filehash = field_attachment[0]['checksum']
|
||||
if model != 'ir.attachment':
|
||||
field_attachment = self.env['ir.attachment'].sudo().search_read(domain=[('res_model', '=', model), ('res_id', '=', record.id), ('res_field', '=', field)], fields=['datas', 'mimetype', 'checksum'], limit=1)
|
||||
if field_attachment:
|
||||
mimetype = field_attachment[0]['mimetype']
|
||||
content = field_attachment[0]['datas']
|
||||
filehash = field_attachment[0]['checksum']
|
||||
else:
|
||||
mimetype = record['mimetype']
|
||||
content = record['datas']
|
||||
filehash = record['checksum']
|
||||
|
||||
if not content:
|
||||
content = record[field] or ''
|
||||
|
||||
Reference in New Issue
Block a user