Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 6 years ago

#20021 closed defect (bug) (invalid)

wp_load_alloptions() does not cache result when MultiSite is enabled

Reported by: gcorne Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: Cache API Keywords: has-patch dev-feedback
Focuses: Cc:


On a MultiSite installation, wp_load_alloptions() does not cache the results in the object cache. This results in a large number of additional queries, especially during wp-admin requests. One real world test resulted in 445 fewer queries and a reduction of over 100ms of time spent querying the database.

Note: Because WP_INSTALLING is defined when using the WP Test Suite, it is currently not possible to write test cases.

Attachments (1)

wp-load-alloptions.patch (2.5 KB) - added by gcorne 10 years ago.

Download all attachments as: .zip

Change History (7)

#1 in reply to: ↑ description @duck_
10 years ago

  • Keywords reporter-feedback added

Replying to gcorne:

On a MultiSite installation, wp_load_alloptions() does not cache the results in the object cache

Only when is_multisite() AND defined( 'WP_INSTALLING' ) are the options not cached. On a local multisite installation the number of queries didn't increase when calling wp_load_alloptions() or get_option( 'rewrite_rules' ) multiple times.

It seems like something else must be going on to cause your issue.

#2 @gcorne
10 years ago

  • Keywords dev-feedback added; reporter-feedback removed


Please see option.php:138 and option.php:152. When getting/setting the cache key pair, the conditional uses OR not AND.

if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
     // check cache
     // don't touch the cache

#3 follow-up: @gcorne
10 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Sorry for the noise.

#4 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted

#5 in reply to: ↑ 3 @TocydLive
8 years ago

Replying to gcorne:

Sorry for the noise.

Hi Gregory,

From my point of view, this post is not noise, because your patch seem's to correct one incorrect behavior on my subfolder multisite installation...

Briefly, when I try to use get_blog_option, a call is made to wp_load_alloptions and always return the site options instead of the blog option value...

You're post is pointing out that this criteria (see below) is use to determine if the cache is needed to be loaded again or not... And as it was suppose to, on my installation WP_INSTALLING is not set and is_multisite() return true so it's resulting in a cache check

if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
     // check cache
     // don't touch the cache

The problem is that the cache is used to return options value but this return the site cache options and not the blog cache options as they have not been loaded yet...If I force the site to refresh the cache by defining WP_INSTALLING, the correct value are returned... When I unset the WP_INSTALLING, the buging behavior come back...

Meanwhile, If I use your patch, the wp_load_alloptions work like as I expect and the get_blog_option finally return the correct blog option value...

Here is my two questions:

1- Did you know another cause that can explain the wp_load_alloptions behavior to not working properly on a multisite(sub-folder) configuration .... (Not loading properly blog options in cache)
2- As your patch work for me, does it is correct to use it ?

Thank's for sharing your expertise!


#6 @SergeyBiryukov
6 years ago

#35096 was marked as a duplicate.

Note: See TracTickets for help on using tickets.