[IMP] product: reduce forced cache invalidation & flushes

write call on product.template.attribute.line with an active value specified
will trigger cache invalidation & flush even if no record is specified in
the call.

_create_variant_ids is called on multiple places, including the unlink
of product.template.attribute.line records.  In this flow, self might
be an empty recordset, and there is no need to trigger early flushes and
cache invalidation if self is empty.

Part-of: odoo/odoo#84055
This commit is contained in:
Victor Feyens
2022-02-07 15:24:49 +00:00
parent 85268e1ae7
commit e51537a430
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -314,7 +314,7 @@ class ProductTemplateAttributeLine(models.Model):
# We catch all kind of exceptions to be sure that the operation
# doesn't fail.
ptal_to_archive += ptal
ptal_to_archive.write({'active': False})
ptal_to_archive.action_archive() # only calls write if there are records
# For archived lines `_update_product_template_attribute_values` is
# implicitly called during the `write` above, but for products that used
# unlinked lines `_create_variant_ids` has to be called manually.
@@ -575,6 +575,9 @@ class ProductTemplate(models.Model):
return prices
def _create_variant_ids(self):
if not self:
return
self.flush()
Product = self.env["product.product"]