WordPress.org

Making WordPress.org

Changeset 5541


Ignore:
Timestamp:
06/05/2017 10:52:15 PM (4 years ago)
Author:
iandunn
Message:

Events: Select countries from countrycodes to improve performance

See #2823
Props dd32

File:
1 edited

Legend:

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

    r5540 r5541  
    722722    global $wpdb;
    723723
    724     $country = $wpdb->get_row( $wpdb->prepare( "
    725         SELECT country_short, country_long
    726         FROM ip2location
     724    $field = 'name';
     725
     726    if ( strlen( $country_name ) == 2 ) {
     727        $field = 'country';
     728    }
     729
     730    return $wpdb->get_row( $wpdb->prepare( "
     731        SELECT
     732            country as country_short,
     733            name as country_long
     734        FROM countrycodes
    727735        WHERE
    728             country_long  = %s OR
    729             country_short = %s
     736            $field = %s
    730737        LIMIT 1",
    731         $country_name,
    732738        $country_name
    733739    ), 'ARRAY_A' );
    734 
    735     // Convert all errors to boolean false for consistency
    736     if ( empty( $country ) ) {
    737         $country = false;
    738     }
    739 
    740     return $country;
    741740}
    742741
Note: See TracChangeset for help on using the changeset viewer.