Skip to content

Commit

Permalink
Improve cache performance. (#11489)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdodd authored and kraftbj committed Mar 5, 2019
1 parent febd6c6 commit 0923e43
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions modules/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -1754,12 +1754,11 @@ function stats_get_from_restapi( $args = array(), $resource = '' ) {
// Do the dirty work.
$response = Jetpack_Client::wpcom_json_api_request_as_blog( $endpoint, $api_version, $args );
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
// If bad, just return it, don't cache.
return $response;
$data = array();
} else {
$data = json_decode( wp_remote_retrieve_body( $response ) );
}

$data = json_decode( wp_remote_retrieve_body( $response ) );

// Expire old keys.
foreach ( $stats_cache as $k => $cache ) {
if ( ! is_array( $cache ) || ( 5 * MINUTE_IN_SECONDS ) < time() - key( $cache ) ) {
Expand Down

0 comments on commit 0923e43

Please sign in to comment.