[IMP] models, fields: initialize cache to None for related fields
This makes sense because in `create` the "previous" value of a field is obviously non-existent. This avoids having to fetch pre-existing attachments when they are known to be inexistent, which optimizes stored related binary that are computed post-insert.
This commit is contained in:
committed by
Sébastien Theys
parent
9112972e15
commit
f047425b82
+11
-5
@@ -1948,15 +1948,21 @@ class Binary(Field):
|
||||
records = cache.get_records_different_from(records, self, cache_value)
|
||||
if not records:
|
||||
return records
|
||||
if self.store:
|
||||
# determine records that are known to be not null
|
||||
not_null = cache.get_records_different_from(records, self, None)
|
||||
|
||||
cache.update(records, self, [cache_value] * len(records))
|
||||
|
||||
# retrieve the attachments that store the values, and adapt them
|
||||
if self.store:
|
||||
atts = records.env['ir.attachment'].sudo().search([
|
||||
('res_model', '=', self.model_name),
|
||||
('res_field', '=', self.name),
|
||||
('res_id', 'in', records.ids),
|
||||
])
|
||||
atts = records.env['ir.attachment'].sudo()
|
||||
if not_null:
|
||||
atts = atts.search([
|
||||
('res_model', '=', self.model_name),
|
||||
('res_field', '=', self.name),
|
||||
('res_id', 'in', records.ids),
|
||||
])
|
||||
if value:
|
||||
# update the existing attachments
|
||||
atts.write({'datas': value})
|
||||
|
||||
@@ -3726,6 +3726,8 @@ Record ids: %(records)s
|
||||
for field in self._fields.values():
|
||||
if field.type in ('one2many', 'many2many'):
|
||||
self.env.cache.set(record, field, ())
|
||||
elif field.related and not field.column_type:
|
||||
self.env.cache.set(record, field, field.convert_to_cache(None, record))
|
||||
# DLE P123: `test_adv_activity`, `test_message_assignation_inbox`, `test_message_log`, `test_create_mail_simple`, ...
|
||||
# Set `mail.message.parent_id` to False in cache so it doesn't do the useless SELECT when computing the modified of `child_ids`
|
||||
# in other words, if `parent_id` is not set, no other message `child_ids` are impacted.
|
||||
|
||||
Reference in New Issue
Block a user