[wp-trac] [WordPress Trac] #43160: Reduce wp-admin/update-core.php load time by half
WordPress Trac
noreply at wordpress.org
Thu Jan 25 23:10:14 UTC 2018
#43160: Reduce wp-admin/update-core.php load time by half
-----------------------------------------+-----------------------------
Reporter: lano1106 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Upgrade/Install | Version: 4.9.2
Severity: normal | Keywords:
Focuses: administration, performance |
-----------------------------------------+-----------------------------
I had this problem where loading this page was taking over a minute.
It turns out that this is caused by premium plugins that makes remote
calls to validate license and/or verify the existence of update.
My whole journey is documented here:
https://wordpress.org/support/topic/displaying-wp-admin-update-core-php-
takes-about-50-secs/
There is not much that can be done about that but this can be mitigated a
lot when you realise that wp_update_plugins() calls set_site_transient()
twice and this is where the expensive hook calls are made.
So here is my attempt to improve the situation:
{{{
$ diff wp-includes/option.php{.orig,}
1721a1722,1759
> * Set/update the value of a site transient without calling the
sometimes expensive hooks.
> *
> * This is particularly for the special case of wp_update_plugins()
where set_site_transient() was called twice
> * and the first time was only for setting up the last_checked
update_plugins option.
> *
> * @since 4.9.2
> *
> * @see wp_update_plugins()
> *
> * @param string $transient Transient name. Expected to not be SQL-
escaped. Must be
> * 167 characters or fewer in length.
> * @param mixed $value Transient value. Expected to not be SQL-
escaped.
> * @param int $expiration Optional. Time until expiration in seconds.
Default 0 (no expiration).
> * @return bool False if value was not set and true if value was set.
> */
> function set_site_transient_nohook( $transient, $value, $expiration = 0
) {
>
> $expiration = (int) $expiration;
>
> if ( wp_using_ext_object_cache() ) {
> $result = wp_cache_set( $transient, $value, 'site-
transient', $expiration );
> } else {
> $transient_timeout = '_site_transient_timeout_' .
$transient;
> $option = '_site_transient_' . $transient;
> if ( false === get_site_option( $option ) ) {
> if ( $expiration )
> add_site_option( $transient_timeout,
time() + $expiration );
> $result = add_site_option( $option, $value );
> } else {
> if ( $expiration )
> update_site_option( $transient_timeout,
time() + $expiration );
> $result = update_site_option( $option, $value );
> }
> }
> return $result;
> }
>
> /**
1767,1781c1805
< if ( wp_using_ext_object_cache() ) {
< $result = wp_cache_set( $transient, $value, 'site-
transient', $expiration );
< } else {
< $transient_timeout = '_site_transient_timeout_' .
$transient;
< $option = '_site_transient_' . $transient;
< if ( false === get_site_option( $option ) ) {
< if ( $expiration )
< add_site_option( $transient_timeout,
time() + $expiration );
< $result = add_site_option( $option, $value );
< } else {
< if ( $expiration )
< update_site_option( $transient_timeout,
time() + $expiration );
< $result = update_site_option( $option, $value );
< }
< }
---
> $result = set_site_transient_nohook( $transient, $value,
$expiration );
$ diff wp-includes/update.php{.orig,}
68c68
< set_site_transient( 'update_core', $current );
---
> set_site_transient_nohook( 'update_plugins', $current );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43160>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list