Making WordPress.org


Ignore:
Timestamp:
08/13/2020 08:23:48 PM (5 years ago)
Author:
iandunn
Message:

Events: Get next discussion group from database.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/index.php

    r10167 r10168  
    13341334             * `wp_cache_get()` from the `memcached` plugin doesn't support the `$found` parameter, so this has to be
    13351335             * done manually.
     1336             *
     1337             * todo $found is now available as of r16106-dotorg.
    13361338             */
    13371339            $next_online_camp = 'none scheduled';
     
    13621364 */
    13631365function pin_next_workshop_discussion_group( $events, $user_agent ) {
     1366    global $wpdb, $cache_group, $cache_life;
     1367
    13641368    if ( ! is_client_core( $user_agent ) ) {
    13651369        return $events;
    13661370    }
    13671371
    1368     if ( time() <= strtotime( '2020-08-13 2pm PDT' ) ) {
    1369         array_unshift(
    1370             $events,
    1371             array(
     1372    $cache_key             = 'next_workshop_discussion_group';
     1373    $next_discussion_group = wp_cache_get( $cache_key, $cache_group, false, $found );
     1374
     1375    if ( ! $found ) {
     1376        $raw_discussion_group = $wpdb->get_row( "
     1377            SELECT `title`, `url`, `meetup`, `meetup_url`, `date_utc`, `end_date`, `country`, `latitude`, `longitude`
     1378            FROM `wporg_events`
     1379            WHERE
     1380                type       = 'meetup'    AND
     1381                meetup_url = 'https://www.meetup.com/learn-wordpress-discussions/' AND
     1382                status     = 'scheduled' AND
     1383                location   = 'online'    AND
     1384                date_utc BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 WEEK
     1385            ORDER BY `date_utc` ASC
     1386            LIMIT 1"
     1387        );
     1388
     1389        if ( isset( $raw_discussion_group->url ) ) {
     1390            $next_discussion_group = array(
    13721391                'type'       => 'meetup',
    1373                 'title'      => 'Discussion Group: Introduction to Contributing to WordPress',
    1374                 'url'        => 'https://www.meetup.com/learn-wordpress-discussions/events/272512607/',
    1375                 'meetup'     => 'Learn WordPress',
    1376                 'meetup_url' => 'https://www.meetup.com/learn-wordpress-discussions/',
    1377                 'date'       => '2020-08-13 14:00:00',
    1378                 'end_date'   => '2020-08-13 15:00:00',
     1392                'title'      => $raw_discussion_group->title,
     1393                'url'        => $raw_discussion_group->url,
     1394                'meetup'     => $raw_discussion_group->meetup,
     1395                'meetup_url' => $raw_discussion_group->meetup_url,
     1396                'date'       => $raw_discussion_group->date_utc,
     1397                'end_date'   => $raw_discussion_group->end_date,
    13791398
    13801399                'location'   => array(
    13811400                    'location'  => 'Online',
    1382                     'country'   => 'US',
    1383                     'latitude'  => 37.78,
    1384                     'longitude' => -122.42,
     1401                    'country'   => $raw_discussion_group->country,
     1402                    'latitude'  => (float) $raw_discussion_group->latitude,
     1403                    'longitude' => (float) $raw_discussion_group->longitude,
    13851404                )
    1386             )
    1387         );
     1405            );
     1406        }
     1407
     1408        /*
     1409         * This intentionally stores a cache value when there are 0 results, because that's a normal condition;
     1410         * i.e., there aren't currently any discussion groups events on the schedule. If nothing were cached in
     1411         * that situation, then this would run a query on every request, which wouldn't be performant at scale.
     1412         */
     1413        wp_cache_set( $cache_key, $next_discussion_group, $cache_group, $cache_life );
     1414    }
     1415
     1416    if ( isset( $next_discussion_group['url'] ) ) {
     1417        array_unshift( $events, $next_discussion_group );
    13881418    }
    13891419
Note: See TracChangeset for help on using the changeset viewer.