Make WordPress Core

Changeset 42586


Ignore:
Timestamp:
01/24/2018 04:31:40 AM (7 years ago)
Author:
dd32
Message:

Updates: Only trigger Background Update processes from within the core update check when a core autoupdate is on offer.

This change reduces the number of API calls which WordPress makes to api.wordpress.org during release windows.

Previously the background updates would run upon every core update transient refresh, however now they'll only run if there's an update available.
The change also increases the cache period for plugin & theme checks when running via the cron, from never-cache to 2 hours, which should hopefully reduce the number of needless API calls.

Merges [42584] to the 4.9 branch.
Fixes #43103 for 4.9.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/update.php

    r41967 r42586  
    169169    }
    170170
    171     $offers = $body['offers'];
     171    $offers          = $body['offers'];
     172    $has_auto_update = false;
    172173
    173174    foreach ( $offers as &$offer ) {
     
    183184        $offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale',
    184185            'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email', 'support_email', 'new_files' ), '' ) );
     186
     187        if ( 'autoupdate' == $offer->response ) {
     188            $has_auto_update = true;
     189        }
    185190    }
    186191
     
    204209
    205210    // Trigger background updates if running non-interactively, and we weren't called from the update handler.
    206     if ( $doing_cron && ! doing_action( 'wp_maybe_auto_update' ) ) {
    207         do_action( 'wp_maybe_auto_update' );
     211    if ( $doing_cron && $has_auto_update && ! doing_action( 'wp_maybe_auto_update' ) ) {
     212        include_once( ABSPATH . '/wp-admin/includes/update.php' );
     213
     214        // Only trigger background updates if an acceptable autoupdate is on offer, avoids needless extra API calls.
     215        if ( find_core_auto_update() ) {
     216            do_action( 'wp_maybe_auto_update' );
     217        }
    208218    }
    209219}
     
    260270        default :
    261271            if ( $doing_cron ) {
    262                 $timeout = 0;
     272                $timeout = 2 * HOUR_IN_SECONDS;
    263273            } else {
    264274                $timeout = 12 * HOUR_IN_SECONDS;
     
    444454            break;
    445455        default :
    446             $timeout = $doing_cron ? 0 : 12 * HOUR_IN_SECONDS;
     456            if ( $doing_cron ) {
     457                $timeout = 2 * HOUR_IN_SECONDS;
     458            } else {
     459                $timeout = 12 * HOUR_IN_SECONDS;
     460            }
    447461    }
    448462
Note: See TracChangeset for help on using the changeset viewer.