[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:
@@ -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"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user