Opened 9 years ago
Closed 9 years ago
#35454 closed defect (bug) (duplicate)
`lazyload_term_meta` is called many time when calling `get_term_metadata`
Reported by: | sfai05 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4 |
Component: | Query | Keywords: | |
Focuses: | performance | Cc: |
Description
Step to reproduce :
Call WP_Query
more then one time in a same request, then action lazyload_term_meta
will hook to filter get_term_metadata
more then one time.
Line 3633 in wp-includes/query.php
Hugely affect performance if you have many custom taxonomy.
Change History (6)
#2
@
9 years ago
Sure. I am running Wordpress 4.4 with Memcached.
I found this problem coz my admin dashboard take super long time to response. Then I find that the memcache get request on the dashboard is much higher then before ( > 4000 for loading one page ).
I run three WP_Query
on different dashboard widget. Some of the widget will do get_term_meta
The problem is the function lazyload_term_meta
is added to hook get_term_metadata
duplicated if you called WP_Query
for more then one time. So when you run get_term_meta
afterward, the action lazyload_term_meta
will be triggered multiple times. And in the function lazyload_term_meta
you will do multiple Memcache get depends on how many taxonomy you have created.
I only do ~40 get_term_meta
it already crashed my memcache server.
Now I set the flag update_post_term_cache
to false
in WP_Query
to keep my server running.
#3
@
9 years ago
@sfai05 - Thanks for the details.
I'm struggling to see whether this is a fundamental architectural problem with the lazyloading technique, or whether there's a race condition that's causing many more cache checks than is required. Maybe you can help me figure this out.
WP_Query::lazyload_term_meta()
is designed to bail when $this->updated_term_meta_cache
is true. However, this flag doesn't get set until the end of the method. I wonder if this fact, combined with lots of calls to get_term_meta()
, is causing get_object_term_cache()
to be called more often than it should. Two things to look at:
- How many times is
lazyload_term_meta()
being called? (It should be once for every call toget_term_meta()
.) And how many times is it getting past the$this->update_term_meta_cache
flag? (It should be once for eachWP_Query
loop previously loaded on the page.) - If you move the
$this->updated_term_meta_cache = true
check to the top of the method - just before the// We can only lazyload...
comment - does it help?
Hi @sfai05 - Welcome to WordPress Trac!
Can you say more about this? Have you done any detailed profiling to see exactly what's affecting performance? Is
lazyload_term_meta()
triggering lots of database queries? Or is it the cache causing excessive cache reads? Are you running a persistent object cache (Memcached, Redis, etc)?