Making WordPress.org

Changeset 13367


Ignore:
Timestamp:
03/21/2024 06:01:07 AM (3 years ago)
Author:
dd32
Message:

Registration: Admin UI: Optimize the searches for lookups by email/ip/country, and prime the user caches in bulk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/class-user-registrations-list-table.php

    r13288 r13367  
    117117
    118118                if ( isset( $_GET['s'] ) && 'all' != $view ) {
    119                          $search_like = '%' . $wpdb->esc_like( wp_unslash( $_GET['s'] ) ) . '%';
    120                          $where .= $wpdb->prepare(
    121                                  " AND (
    122                                         registrations.user_login LIKE %s OR
    123                                         registrations.user_email LIKE %s OR
    124                                         registrations.meta LIKE %s OR
    125                                         description.meta_value LIKE %s
    126                                 )",
    127                                  $search_like, $search_like, $search_like, $search_like
    128                         );
     119                        $where .= ' ';
     120
     121                        $search_term = wp_unslash( $_GET['s'] );
     122                        $search_like = '%' . $wpdb->esc_like( $search_term ) . '%';
     123
     124                        // Limit searches to where they're likely, for performance.
     125                        if ( str_contains( $search_term, '@' ) ) {
     126                                // Looks like an email, so just search the emails.
     127                                $where .= $wpdb->prepare(
     128                                        "AND registrations.user_email LIKE %s",
     129                                        $search_like
     130                                );
     131                        } elseif (
     132                                // If it looks like an IP
     133                                preg_match( '/^\d{1,3}\.[0-9.]*$/', $search_term ) ||
     134                                // Or it looks like a country code,
     135                                preg_match( '/^[A-Z]{2}/', $search_term )
     136                        ) {
     137                                // then only look in metadata.
     138                                $where .= $wpdb->prepare(
     139                                        "AND registrations.meta LIKE %s",
     140                                        $search_like
     141                                );
     142                        } else {
     143                                // Otherwise, search everything.
     144                                $where .= $wpdb->prepare(
     145                                        "AND (
     146                                                registrations.user_login LIKE %s OR
     147                                                registrations.user_email LIKE %s OR
     148                                                registrations.meta LIKE %s OR
     149                                                description.meta_value LIKE %s
     150                                        )",
     151                                        $search_like, $search_like, $search_like, $search_like
     152                                );
     153                        }
    129154                }
    130155
    … …  
    137162                }
    138163
    139                 if ( 'banned-users' === $view ?: ( $_REQUEST['view'] ?? 'all' ) ) {
     164                if ( 'banned-users' === ( $view ?: ( $_REQUEST['view'] ?? 'all' ) ) ) {
    140165                        $join .= " LEFT JOIN {$wpdb->usermeta} notes ON users.ID = notes.user_id AND notes.meta_key = '_wporg_bbp_user_notes'";
    141166                }
    … …  
    208233                $total_items = $wpdb->get_var( 'SELECT FOUND_ROWS()' );
    209234
     235                // Prime the user lookups.
     236                $logins = wp_list_pluck( wp_list_filter( $this->items, [ 'created' => true ] ), 'user_login' );
     237                if ( $logins ) {
     238                        get_users( [
     239                                'login__in' => $logins,
     240                                'fields'    => 'all_with_meta'
     241                        ] );
     242                }
     243
    210244                foreach ( $this->items as $i => $item ) {
    211                         $this->items[$i]->user       = $item->created ? get_user_by( 'slug', $item->user_login ) : false;
     245                        $this->items[$i]->user       = $item->created ? get_user_by( 'login', $item->user_login ) : false;
    212246                        $this->items[$i]->pending_id = (int) $this->items[$i]->pending_id;
    213247                        $this->items[$i]->cleared    = (int) $this->items[$i]->cleared;
Note: See TracChangeset for help on using the changeset viewer.