Rewrite WP_User_Query to use JOIN instead of subquery. See #14572
git-svn-id: http://svn.automattic.com/wordpress/trunk@15579 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9a9e872597
commit
6fd94cd065
|
@ -4244,10 +4244,9 @@ function _wp_search_sql($string, $cols) {
|
||||||
*
|
*
|
||||||
* @param array $queries An array of queries
|
* @param array $queries An array of queries
|
||||||
* @param string $meta_id_column The column that holds the object id
|
* @param string $meta_id_column The column that holds the object id
|
||||||
* @param string $table Which meta table to look in
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function _wp_meta_sql( $queries, $meta_id_column, $table ) {
|
function _wp_meta_sql( $queries, $meta_id_column ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$clauses = array();
|
$clauses = array();
|
||||||
|
@ -4278,9 +4277,7 @@ function _wp_meta_sql( $queries, $meta_id_column, $table ) {
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
return "
|
return "
|
||||||
SELECT $meta_id_column
|
AND CASE meta_key
|
||||||
FROM $table
|
|
||||||
WHERE CASE meta_key
|
|
||||||
" . implode( "\n", $clauses ) . "
|
" . implode( "\n", $clauses ) . "
|
||||||
END
|
END
|
||||||
GROUP BY $meta_id_column
|
GROUP BY $meta_id_column
|
||||||
|
|
|
@ -463,10 +463,11 @@ class WP_User_Query {
|
||||||
|
|
||||||
$meta_queries[] = wp_array_slice_assoc( $qv, array( 'meta_key', 'meta_value', 'meta_compare' ) );
|
$meta_queries[] = wp_array_slice_assoc( $qv, array( 'meta_key', 'meta_value', 'meta_compare' ) );
|
||||||
|
|
||||||
$meta_query_sql = _wp_meta_sql( $meta_queries, 'user_id', $wpdb->usermeta );
|
$meta_query_sql = _wp_meta_sql( $meta_queries, 'user_id' );
|
||||||
|
|
||||||
if ( !empty( $meta_query_sql ) ) {
|
if ( !empty( $meta_query_sql ) ) {
|
||||||
$this->query_where .= " AND $wpdb->users.ID IN ($meta_query_sql)";
|
$this->query_from .= " INNER JOIN $wpdb->usermeta ON ($wpdb->users.ID = $wpdb->usermeta.user_id)";
|
||||||
|
$this->query_where .= $meta_query_sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($qv['include']) ) {
|
if ( !empty($qv['include']) ) {
|
||||||
|
@ -490,13 +491,13 @@ class WP_User_Query {
|
||||||
function query() {
|
function query() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$this->results = $wpdb->get_col("SELECT DISTINCT($wpdb->users.ID)" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit);
|
$this->results = $wpdb->get_col("SELECT $wpdb->users.ID" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit);
|
||||||
|
|
||||||
if ( !$this->results )
|
if ( !$this->results )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( $this->query_vars['count_total'] )
|
if ( $this->query_vars['count_total'] )
|
||||||
$this->total_users = $wpdb->get_var("SELECT COUNT(DISTINCT($wpdb->users.ID))" . $this->query_from . $this->query_where);
|
$this->total_users = $wpdb->get_var("SELECT COUNT($wpdb->users.ID)" . $this->query_from . $this->query_where);
|
||||||
|
|
||||||
if ( 'all' == $this->query_vars['fields'] ) {
|
if ( 'all' == $this->query_vars['fields'] ) {
|
||||||
cache_users($this->results);
|
cache_users($this->results);
|
||||||
|
|
Loading…
Reference in New Issue