Found when reviewing #2835629: Allow altering the default variation.

We call ProductInterface::getDefaultVariation in several places. Each time we loop through the product's variations and pick the first variation that is published and accessible. After the first check we already have the variations in the storage's static cache and should have access check static cache available.

This is probably a micro-optimization as the entity type manager has a static cache of handlers, the access checks are in the static cache, along with the previously loaded variations.

But it wouldn't hurt to explore.

CommentFileSizeAuthor
#3 use_a_static_cache_i-3135918-3.patch1.38 KBmglaman

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Discussed with rszrama. We should use a defaultVariation property on the product class. If we used static inside of the method, it would be used across instances 😱.

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new1.38 KB

Here's a patch. Property documentation to be bikeshedded. First, I want to see if this breaks anything.

Status: Needs review » Needs work

The last submitted patch, 3: use_a_static_cache_i-3135918-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mglaman’s picture

mglaman’s picture

Status: Needs work » Needs review

IEF fixed

  • mglaman committed a41c7b2 on 8.x-2.x
    Issue #3135918 by mglaman: Use a static cache in getDefaultVariation for...
mglaman’s picture

Status: Needs review » Fixed

Committed, so we now we can just fetch from the property after the first check.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.