Making WordPress.org

Changeset 8919


Ignore:
Timestamp:
06/05/2019 04:52:17 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Search: Remove debug and add specific errors in the case of a non-200 response.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/site-search/jetpack-search.php

    r8904 r8919  
    226226        $cache_key    = md5( $json_es_args );
    227227        $lock_key     = 'lock-' . $cache_key;
    228         $count_key    = 'count-' . $cache_key;
    229228
    230229        // If the Query args were not able to be encoded, bail.
     
    247246
    248247        if ( $do_fresh_request ) {
    249             // Keep track of the number of concurrent requests for this key
    250             wp_cache_set( $count_key, 1, self::CACHE_GROUP, 60 );
    251248
    252249            // If the error volume is high, there's a proportionally lower chance that we'll actually attempt to hit the API.
     
    276273                    $this->search_error( 'http error ' . $request->get_error_message(), E_USER_WARNING );
    277274                } else {
    278                     $this->search_error( 'http status ' . wp_remote_retrieve_response_code( $request ), E_USER_WARNING );
     275                    $es_error = json_decode( wp_remote_retrieve_body( $request ), true );
     276
     277                    $this->search_error(
     278                        sprintf( 'http status %d %s %s',
     279                            wp_remote_retrieve_response_code( $request ),
     280                            $es_error['error'] ?? '',
     281                            $es_error['message'] ?? ''
     282                        ),
     283                        E_USER_WARNING
     284                    );
    279285                }
    280286
     
    314320            // Stampede protection has kicked in, AND we have no stale cached value to display. That's bad - possibly indicates cache exhaustion
    315321            if ( false === $response ) {
    316                 // Keep a track of how many cache stampede's happen per minute.
    317                 wp_cache_incr( 'search-stampede-failures', 1, self::CACHE_GROUP ) || wp_cache_set( 'search-stampede-failures', 1, self::CACHE_GROUP, 60 );
    318 
    319                 // Include the number of times this branch has been hit
    320                 $request_count = wp_cache_incr( $count_key, 1, self::CACHE_GROUP );
    321                 trigger_error( 'Plugin directory search: no cached results available during stampede. Requests: ' . $request_count, E_USER_WARNING );
     322                trigger_error( 'Plugin directory search: no cached results available during stampede.', E_USER_WARNING );
    322323            }
    323324        }
Note: See TracChangeset for help on using the changeset viewer.