In Terms Indexablequery_db
, for term count, use wp_count_terms()
instead of WP_Term_Query
#3791
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.
Description of the Change
We're seeing on sites with a very large amount of terms, terms indexing isn't starting because of a query that is being killed:
This is because in
query_db()
for the terms Indexable, we are calling a new instance ofWP_Term_Query
, which ultimately calls_prime_term_caches
and triggers an expensive, unnecessary query: https://github.com/WordPress/WordPress/blob/e99a11600602fbb5282b59227004d61c543d812d/wp-includes/taxonomy.php#L4071It isn't required for the ultimate term count in
$total_objects
, so we should be good to replace it with a simplewp_count_terms()
call (which doesn't ultimately call_prime_term_caches()
due to an early return).Aside: I've also set
hierarchical
tofalse
because I'm seeing that it performs a no limit query which, on a site with a lot of terms, is being killed: https://github.com/WordPress/WordPress/blob/e99a11600602fbb5282b59227004d61c543d812d/wp-includes/class-wp-term-query.php#L635-L644. I don't think it's the hierarchical structure is necessary for indexing (correct me if I'm wrong).How to test the Change
wp vip-search index --indexables=term
Changelog Entry
Changed - counts are now calculated with
wp_count_terms()
in Indexable Termsquery_db
Credits
Props @rebeccahum
Checklist: