#36953 closed defect (bug) (fixed)
Meta lazyloading can cause excessive calls to object cache
Reported by: | boonebgorges | Owned by: | DBrumbaugh10Up |
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | good-first-bug needs-unit-tests has-patch |
Focuses: | performance | Cc: |
Description
WP_Query
calls wp_queue_posts_for_term_meta_lazyload()
, which in turn grabs the {$taxonomy}_relationships
cache for each found post, for each taxonomy that they belong to. So if you're fetching 20 items, and each item is in 10 taxonomies, the process will require 200 cache gets. This is in addition to the dozens of other other cache priming gets that happens in WP_Query
.
On very high traffic sites running an object cache backend, the high volume calls to the cache can cause performance issues.
A truly general fix would be wp_cache_get_multi()
, which would allow functions like this to reduce cache roundtrips by one or two orders of magnitude. See #20875.
In the meantime, two things to explore:
WP_Query
decides whether to queue posts for termmeta lazyloading based on the value of 'update_term_meta_cache'. This should be more fine-grained. A newWP_Query
parameterlazyload_term_meta
, which would default to the value ofupdate_term_meta
, seems appropriate. This way, very high-traffic sites that don't use termmeta and thus don't need to lazyload it can disable the feature in a targeted way, via apre_get_posts
callback.- Look for ways to cut back on cache queries in the lazyload process. Not sure if that's feasible, since different posts keep their taxonomy relationships in different cache buckets, but it's worth looking into.
1 should be doable for 4.6.
cc @patrickgarman, who brought this to my attention.
Attachments (1)
Change History (11)
#4
@
8 years ago
- Keywords has-patch added; needs-patch removed
@boonebgorges The patch implements option #1 that you've listed as far as I can understand. What I'm missing I guess is why a site can't just set update_term_meta_cache to "false" in the pre_get_posts call back?
Or did I miss your intent?
#5
@
8 years ago
So was term_meta_lazyload depreciated in WP 4.5?
No. Term meta lazyloading was introduced in 4.5.
@boonebgorges The patch implements option #1 that you've listed as far as I can understand
Thanks. I mistyped - I meant that the value of lazyload_term_meta
should fall back on the value of update_term_meta_cache
.
What I'm missing I guess is why a site can't just set update_term_meta_cache to "false" in the pre_get_posts call back?
This can already be done. But it makes it impossible to prime the term cache without priming the termmeta cache.
#7
@
8 years ago
- Owner set to DBrumbaugh10Up
- Status changed from new to assigned
Assigning to mark the good-first-bug as "claimed".
#8
@
8 years ago
- Resolution set to fixed
- Status changed from assigned to closed
Going to mark this as resolved for 4.6. We can explore further improvements (especially integration with cache multi-get - #20875) in future releases.
Less cache gets would be a good thing.