Opened 8 years ago
Closed 7 years ago
#41662 closed defect (bug) (fixed)
Don't prime menu item cache if a persistent cache is being used
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Menus | Keywords: | has-patch commit |
Focuses: | performance | Cc: |
Description
In terms of #12734 a r14560 have been introduced. However, while the commit message says following:
Don't prime menu item cache if a persistent cache is being used. Prime the menu item cache only on the first call to wp_get_nav_menu_items(). Avoids unneeded queries when wp_get_nav_menu_items() is called repeatedly. see #12734
The code introduced in the revision says following:
// Get all posts and terms at once to prime the caches
if ( empty($fetched[$menu->term_id]) || $_wp_using_ext_object_cache ) {
The condition check for whether the currently processed term_id
has already been fetched (eg.: during repeated call to wp_nav_menu
) by checking for the key in static variable $fetched
or whether external object cache is in use.
The, imho, faulty part of the condition is the || $_wp_using_ext_object_cache
(or currently used || wp_using_ext_object_cache()
) as it says, prime caches always, in case external object cache is being used.
The conditional, imho, should state && ! wp_using_ext_object_cache()
. Testing this change on a WordPress install without persistent object cache backend shows no difference in behaviour (as expected), and testing the change on the same WordPress install after enabling persistent object cache backend shows decrease in the number of SQL queries performed by wp_nav_menu
call.
@david.binda looks like a logical change based on the description. Have you run phpunit with your changes?