Make WordPress Core

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: davidbinda's profile david.binda Owned by: westonruter's profile westonruter
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.

Attachments (1)

41662.patch (505 bytes) - added by david.binda 8 years ago.

Download all attachments as: .zip

Change History (6)

@david.binda
8 years ago

#1 @welcher
8 years ago

@david.binda looks like a logical change based on the description. Have you run phpunit with your changes?

#2 @welcher
7 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.9

Unit tests passed for me in Travis. I think we're good to go here.

#3 @welcher
7 years ago

  • Keywords commit added

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

#5 @westonruter
7 years ago

  • Owner set to westonruter
  • Resolution set to fixed
  • Status changed from new to closed

In 41982:

Menus: Don't prime nav menu items cache if a persistent cache is being used.

Amends [14560].
Props david.binda.
See #12734.
Fixes #41662.

Note: See TracTickets for help on using tickets.