Describe your bug or feature request.
Currently class ProductVariation
has method getCacheTagsToInvalidate()
/**
* {@inheritdoc}
*/
public function getCacheTagsToInvalidate() {
$tags = parent::getCacheTagsToInvalidate();
// Invalidate the variations view builder and product caches.
return Cache::mergeTags($tags, [
'commerce_product:' . $this->getProductId(),
'commerce_product_variation_view',
]);
}
Tags that end with _view
used by EntityViewBuilder
class and invalidates when entity view display is changed, which is logical. (check EntityViewBuilder::getCacheTags()
)
Method ProductVariation::getCacheTagsToInvalidate()
returns commerce_product_variation_view
tag.
This means, that after updating of product variation, the render cache for all product variations will be invalidated. When you update 1 product variation, the render cache for all product variations is invalidated.
Proposed resolution:
Remove commerce_product_variation_view
tag from the ProductVariation::getCacheTagsToInvalidate()
Comment | File | Size | Author |
---|---|---|---|
#4 | remove-cache-tag-3285023-4.patch | 2.14 KB | _shY |
| |||
#3 | remove-cache-tag-tests-3285023-3.patch | 1.59 KB | _shY |
| |||
#2 | commerce-remove-cache-tag-3285023-2.patch | 567 bytes | _shY |
Comments
Comment #2
_shYComment #3
_shYFound why tests fail.
Tests failed with the patch because after injecting the field to the view display, the cache wasn't clear and the field doesn't display correctly.
Meanwhile, the previous test
testInjectedVariationDefault()
, made almost the same validation, but added a small thing. Submitted product variation view display form after field injection.Comment said:
After saving the view display form, invalidated
commerce_product_variation_view
tag, and everything works fine.So, I added view display form submitting to the
testInjectedVariationFromUrl()
test.Here is a patch only with changes for the Tests, to be sure that it doesn't break anything.
Comment #4
_shYAnd here is a full patch: with tests and cache tag removes.
Comment #5
abrammI can confirm we're using this patch on our project and it passed our QA.
This patch solves a huge performance degradation for sites actively using products/variations displays; e.g. in our case, we have a Search API view displaying rendered products displays. The view was slowing down dramatically due to entity displays cache misses every time any change to products data was made (even if the product being changed is not displayed).
I'll change the status to RTBC but since me and @_shY are working on the same project it'd be good if someone else could take a look as well.
Comment #7
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted!