Make WordPress Core

Opened 12 years ago

Closed 8 years ago

#22846 closed defect (bug) (fixed)

Site transient autoload even when they have expiry time

Reported by: mark-k's profile mark-k Owned by: jeremyfelt's profile jeremyfelt
Milestone: 4.6 Priority: normal
Severity: normal Version: 2.9
Component: Options, Meta APIs Keywords: has-patch has-unit-tests
Focuses: multisite, performance Cc:

Description

I guess set_site_transient should set autoload to NO after calling add_site_option when there is expiration time.

As far as I can see the all of the site transients right now are used only by cron and admin so no reason to auto load

Attachments (3)

22846.diff (432 bytes) - added by thomaswm 8 years ago.
Don't autoload network options
22846.2.diff (649 bytes) - added by thomaswm 8 years ago.
Don't autoload network options
22846.3.diff (2.6 KB) - added by jeremyfelt 8 years ago.

Download all attachments as: .zip

Change History (16)

#1 @webaware
11 years ago

Problem still exists in 3.5.1, meaning all site transients are autoloaded on every page on every site. This includes such broadly useful things as the 'browser_' site transients (only used by wp_check_browser_version() in the dashboard).

#2 @nacin
11 years ago

  • Component changed from Performance to Options and Meta
  • Focuses performance added

#3 @jeremyfelt
11 years ago

  • Focuses multisite added

Related #26929

#4 @DavidAnderson
10 years ago

This problem still exists in 3.9.1.

I was researching why BruteProtect's (http://wordpress.org/plugins/bruteprotect) transients were set to auto-load - a potentially serious performance issue, given the nature of that plugin (one transient created per IP address trying to log in).

#5 @chriscct7
9 years ago

  • Keywords needs-patch added

#6 in reply to: ↑ description ; follow-up: @thomaswm
9 years ago

Replying to mark-k:

I guess set_site_transient should set autoload to NO after calling add_site_option when there is expiration time.

add_site_option does not have an "autoload" parameter. Moreover, the sitemeta table, where site options and site transients are stored, does not have a column called "autoload".

Autoloading of network options happens in wp_load_core_site_options(), but there's a hardcoded list of options which are autoloaded.

$core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );
 
$core_options_in = "'" . implode("', '", $core_options) . "'";
$options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) ); 

So, WordPress does not autoload site transients.

#7 in reply to: ↑ 6 @DavidAnderson
9 years ago

Replying to thomaswm:

So, WordPress does not autoload site transients.

I think you mean "A WordPress multisite install does not autoload site transients". Non-multisite installs do, which is what this bug is about.

#8 follow-up: @jeremyfelt
8 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

This doesn't just impact site transients, but any use of add/update_site_option that expects to fallback to add/update_option option in a single site environment.

We could probably add the autoload parameter to _network_option() and _site_option(), though as mentioned, there is no concept of autoload in $wpdb->sitemeta. We would need to make it clear that the parameter is only used in fallback situations. Is that worth it?

A slightly more weird route (IMO) would be to add the concept of auto loading site meta. wp_load_core_site_options() would then pull from a more dynamic list. I'd hesitate to go here though.

Related: the autoload parameter was added to update_option() in 4.2, #26394.

@thomaswm
8 years ago

Don't autoload network options

#9 in reply to: ↑ 8 ; follow-up: @thomaswm
8 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

Replying to jeremyfelt:

We could probably add the autoload parameter to _network_option() and _site_option(), though as mentioned, there is no concept of autoload in $wpdb->sitemeta.

Alternatively, the code in add_network_option() could be changed so that in single-site installations, it falls back to add_option(), but it sets the $autoload parameter to 'no'. That way, single-site and multisite installations would show the same behaviour. They both wouldn't autoload network options (and transients).

See 22846.2.diff

Last edited 8 years ago by thomaswm (previous) (diff)

@thomaswm
8 years ago

Don't autoload network options

#10 in reply to: ↑ 9 @jeremyfelt
8 years ago

  • Keywords needs-unit-tests needs-testing removed
  • Milestone changed from Future Release to 4.6
  • Owner set to jeremyfelt
  • Status changed from new to reviewing

Replying to thomaswm:

Alternatively, the code in add_network_option() could be changed so that in single-site installations, it falls back to add_option(), but it sets the $autoload parameter to 'no'. That way, single-site and multisite installations would show the same behaviour. They both wouldn't autoload network options (and transients).

+1 Much easier. :)

@jeremyfelt
8 years ago

#11 @jeremyfelt
8 years ago

  • Keywords has-unit-tests added

22846.3.diff adds tests for set_site_transient(), update_network_option(), and add_network_option() to confirm 22846.2.diff

#12 @jeremyfelt
8 years ago

  • Version changed from 3.4.2 to 2.9

Partially introduced with the introduction of set_site_transient() in [12128].

#13 @jeremyfelt
8 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 37223:

Options: Do not set network options to autoload in single site

When multisite is not configured, the _site_transient() and _site_option() functions fallback to _option() and store network "meta/options" in wp_options.

Previously, those calls to _option() did not explicitly set the autoload parameter and anything assigned as a transient or option at the network level would be set to autoload by default, even though autoload is not yet a concept at the network option level.

This changes that behavior and forces the autoload setting to no. If autoload is desired, the single site option functions should be used.

Props thomaswm.
Fixes #22846.

Note: See TracTickets for help on using tickets.