[wp-trac] [WordPress Trac] #41662: Don't prime menu item cache if a persistent cache is being used
WordPress Trac
noreply at wordpress.org
Thu Aug 17 17:55:14 UTC 2017
#41662: Don't prime menu item cache if a persistent cache is being used
--------------------------+-----------------------------
Reporter: david.binda | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: trunk
Severity: normal | Keywords:
Focuses: performance |
--------------------------+-----------------------------
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:
{{{#!php
// 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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41662>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list