Making WordPress.org


Ignore:
Timestamp:
03/07/2018 01:45:38 AM (7 years ago)
Author:
iandunn
Message:

WordCamp QBO: Store classes in site option for reliability.

Storing it in a transient often causes the data to be empty when the QBO connection is unavailable.

This is also a good opportunity to remove some of the unnecessary "middle man" code from the wordcamp-qbo-client experiment, now that it's clear that the tangible drawbacks (lots of unnecessary, duplicated, unintuitive code) are worse than the intangible benefits (future-proofing for the unlikely event that we'll switch to a decentralized hosting model in the future).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo-client/wordcamp-qbo-client.php

    r6505 r6833  
    9191     */
    9292    public static function get_classes() {
    93         $cache_key = md5( 'wordcamp-qbo-client:classes' );
    94         $cache = get_transient( $cache_key );
    95 
    96         if ( $cache !== false )
    97             return $cache;
    98 
    99         $request_url = esc_url_raw( self::$api_base . '/classes/' );
    100         $request_args = array(
    101             'timeout' => self::REMOTE_REQUEST_TIMEOUT,
    102             'headers' => array(
    103                 'Content-Type' => 'application/json',
    104                 'Authorization' => self::_get_auth_header( 'get', $request_url ),
    105             ),
    106         );
    107         $response = wp_remote_get( $request_url, $request_args );
    108 
    109         Logger\log( 'remote_request', compact( 'request_url', 'request_args', 'response' ) );
    110 
    111         $classes = array();
    112 
    113         if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) == 200 ) {
    114             $body = json_decode( wp_remote_retrieve_body( $response ), true );
    115             if ( ! empty( $body ) && is_array( $body ) )
    116                 $classes = $body;
    117         }
    118 
    119         if ( $classes ) {
    120             set_transient( $cache_key, $classes, 12 * HOUR_IN_SECONDS );
    121         }
    122 
    123         return $classes;
     93        return get_site_option( 'wordcamp_qbo_classes' );
    12494    }
    12595
Note: See TracChangeset for help on using the changeset viewer.