diff options
| author | Jeremy Kersten <jke@odoo.com> | 2020-03-26 18:06:57 +0000 |
|---|---|---|
| committer | Romain Derie <rde@odoo.com> | 2020-03-26 18:12:47 +0000 |
| commit | 1606d22d40cd431a02e73bb0661a192bb12edf85 (patch) | |
| tree | 7a59fed29a3248d886655d948cd3e28486c12ff5 /odoo | |
| parent | 6d6b505598413b0d766a8394c7131351ade64266 (diff) | |
[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
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/addons/base/models/ir_http.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py index ece858f5a0f..ba771a95753 100644 --- a/odoo/addons/base/models/ir_http.py +++ b/odoo/addons/base/models/ir_http.py @@ -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 '' |
