Making WordPress.org


Ignore:
Timestamp:
03/29/2019 07:42:38 PM (5 years ago)
Author:
vedjain
Message:

WordPress.org: Use Meetup.com client to respect throttle limit

Meetup API has a throttle limit for API request which Meetup_Client parse and respects. This patch replaces direct API call to Meetup.com with Meetup_Client for caching in events widget so that throttle limits are respected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php

    r8086 r8555  
    521521        }
    522522
     523        require_once( __DIR__ . '/class-meetup-client.php' );
     524        $meetup_client = new Meetup_Client();
     525
     526        if ( ! empty( $meetup_client->error->errors ) ) {
     527            $this->log( 'Failed to instantiate meetup client: ' . wp_json_encode( $meetup_client->error ), true );
     528            return;
     529        }
     530
    523531        foreach ( $chunked_db_events as $group_url => $db_events ) {
    524532            $url_name = trim( wp_parse_url( $group_url, PHP_URL_PATH ), '/' );
    525533
    526             $request_url = sprintf(
    527                 '%s%s/events?page=500&status=upcoming,cancelled&key=%s',
    528                 self::MEETUP_API_BASE_URL,
     534            $events = $meetup_client->get_group_events(
    529535                $url_name,
    530                 MEETUP_API_KEY
     536                array(
     537                    'status' => 'upcoming,cancelled',
     538                )
    531539            );
    532540
    533             $response   = $this->remote_get( $request_url );
    534             $body       = json_decode( wp_remote_retrieve_body( $response ) );
    535             $api_events = wp_list_pluck( $body, 'id' );
    536 
    537541            // Make sure we have a valid API response, to avoid marking events as deleted just because the request failed.
    538             if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
     542            if ( is_wp_error( $events ) ) {
    539543                continue;
    540544            }
    541545
    542             if ( empty( $body[0]->status ) || empty( $api_events[0] ) ) {
    543                 continue;
    544             }
     546            $api_events = wp_list_pluck( $events, 'id' );
    545547
    546548            foreach ( $db_events as $db_event ) {
Note: See TracChangeset for help on using the changeset viewer.