From f70c66520961eaedcfc73b58f707e63160a4df69 Mon Sep 17 00:00:00 2001 From: Pavel Schoffer Date: Wed, 1 Sep 2021 16:44:35 +0200 Subject: [PATCH 1/4] Fix infinit loop --- includes/classes/Command.php | 6 ++++-- includes/classes/Indexable/User/User.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/classes/Command.php b/includes/classes/Command.php index a4654d1734..f32eeba85c 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -830,7 +830,7 @@ function ( $prefix ) use ( $args ) { $query_args = []; $query_args['offset'] = 0; - $query_args['ep_indexing_advanced_pagination'] = ! $no_bulk; + $query_args['ep_indexing_advanced_pagination'] = 'post' === $indexable->slug && ! $no_bulk; if ( ! empty( $args['offset'] ) ) { $query_args['offset'] = absint( $args['offset'] ); @@ -1019,7 +1019,9 @@ function ( $prefix ) use ( $args ) { $peak_memory = ' (Peak: ' . round( memory_get_peak_usage() / 1024 / 1024, 2 ) . 'mb)'; WP_CLI::log( WP_CLI::colorize( '%Y' . esc_html__( 'Memory Usage: ', 'elasticpress' ) . '%N' . $current_memory . $peak_memory ) ); } - } else { + } + + if ( ! $query_args['ep_indexing_advanced_pagination'] ) { // Only increment the offset if not using advanced pagination. // For the advanced pagination should always be 0. // @see Indexable\Post\Post.php::query_db. diff --git a/includes/classes/Indexable/User/User.php b/includes/classes/Indexable/User/User.php index c68ec9db21..1578d446c1 100644 --- a/includes/classes/Indexable/User/User.php +++ b/includes/classes/Indexable/User/User.php @@ -738,7 +738,7 @@ public function query_db( $args ) { * WP_User_Query doesn't let us get users across all blogs easily. This is the best * way to do that. */ - $objects = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->users} %s LIMIT %d, %d", $orderby, (int) $args['offset'], (int) $args['number'] ) ); + $objects = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->users} {$orderby} LIMIT %d, %d", (int) $args['offset'], (int) $args['number'] ) ); return [ 'objects' => $objects, From 5df673bd3b4853812b8e4e8557148c0c3d053fe2 Mon Sep 17 00:00:00 2001 From: Pavel Schoffer Date: Thu, 2 Sep 2021 07:31:05 +0200 Subject: [PATCH 2/4] ignore linting issue --- includes/classes/Indexable/User/User.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/classes/Indexable/User/User.php b/includes/classes/Indexable/User/User.php index 1578d446c1..21baae51ee 100644 --- a/includes/classes/Indexable/User/User.php +++ b/includes/classes/Indexable/User/User.php @@ -737,8 +737,17 @@ public function query_db( $args ) { /** * WP_User_Query doesn't let us get users across all blogs easily. This is the best * way to do that. + * + * The $wpdb->prepare will quate placeholders. + * + * SELECT * FROM table 'ORDER BY col asc'; - mariadb (vipd and local dev-env) doesn't like that + * SELECT * FROM table ORDER BY 'col' 'asc'; - (this is the upstream variant) Vitess (k8s) doesn't like that + * + * We are sanitizing orderby in advance and putting it as a varible to avoid quates. */ + // @codingStandardsIgnoreStart $objects = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->users} {$orderby} LIMIT %d, %d", (int) $args['offset'], (int) $args['number'] ) ); + // @codingStandardsIgnoreStop return [ 'objects' => $objects, From b98737fc41148eda0f26ef958d637e6fb4643154 Mon Sep 17 00:00:00 2001 From: Pavel Schoffer Date: Thu, 2 Sep 2021 10:15:56 +0200 Subject: [PATCH 3/4] revert the offset fix --- includes/classes/Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Command.php b/includes/classes/Command.php index e09fb245e9..a680101511 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -828,7 +828,7 @@ function ( $prefix ) use ( $args ) { $query_args = []; $query_args['offset'] = 0; - $query_args['ep_indexing_advanced_pagination'] = 'post' === $indexable->slug && ! $no_bulk; + $query_args['ep_indexing_advanced_pagination'] = ! $no_bulk; if ( ! empty( $args['offset'] ) ) { $query_args['offset'] = absint( $args['offset'] ); From 80b8f645bbcff315d402705673e9eb82de590ec5 Mon Sep 17 00:00:00 2001 From: Pavel Schoffer Date: Thu, 2 Sep 2021 10:21:11 +0200 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Caleb Burks --- includes/classes/Indexable/User/User.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/includes/classes/Indexable/User/User.php b/includes/classes/Indexable/User/User.php index 21baae51ee..7952345414 100644 --- a/includes/classes/Indexable/User/User.php +++ b/includes/classes/Indexable/User/User.php @@ -738,12 +738,8 @@ public function query_db( $args ) { * WP_User_Query doesn't let us get users across all blogs easily. This is the best * way to do that. * - * The $wpdb->prepare will quate placeholders. - * - * SELECT * FROM table 'ORDER BY col asc'; - mariadb (vipd and local dev-env) doesn't like that - * SELECT * FROM table ORDER BY 'col' 'asc'; - (this is the upstream variant) Vitess (k8s) doesn't like that - * - * We are sanitizing orderby in advance and putting it as a varible to avoid quates. + * The $wpdb->prepare will quote placeholders. + * We are sanitizing orderby in advance and putting it as a variable to avoid quotes. */ // @codingStandardsIgnoreStart $objects = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->users} {$orderby} LIMIT %d, %d", (int) $args['offset'], (int) $args['number'] ) );