Don't prime term cache when no posts are passed #2030
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bugfix
What is the current behavior? (You can also link to an open issue here)
When using a permanent object cache, any cache priming is unnecessary because the items are most likely already in the permanent cache.
To make matters worse, the
Tribe\Utils\Taxonomy::prime_term_cache
method has a major performance problem when called with an empty$posts
array. This is the case, for example, when no future events are to be displayed in the "Events List" widget.In this part of the method:
tribe-common/src/Tribe/Utils/Taxonomy.php
Lines 160 to 165 in 3be81d6
the following values are passed:
This is highly insufficient for systems with a large number of post tags because all post tags will be fetched and passed to
_prime_term_caches()
. On a project with ~12,000 post tags, we had ~100k requests to the cache.What is the new behavior (if this is a feature change)?
If the
$posts
array is empty (i.e. no events are displayed in the widget), bail early and return an empty array. With ~12,000 post tags, we saw a reduction from ~100k requests to ~20k.Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
I don't expect this to be a breaking change.
Other information:
There's an incomplete sentence in the function's DocBlock:
Important to note that
.Tagging some of the maintainers to get visibility: @lucatume, @bordoni, @Camwyn (sorry for the notification spam)