From 06867efdaa37f246d06a7013f564631764e481af Mon Sep 17 00:00:00 2001 From: Gabriel Aramburu Date: Tue, 16 Jun 2026 13:21:14 -0400 Subject: [PATCH] Update tidb-compatibility.php fix to show the users list --- .../tidb-compatibility/tidb-compatibility.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wp/wp-content/plugins/tidb-compatibility/tidb-compatibility.php b/wp/wp-content/plugins/tidb-compatibility/tidb-compatibility.php index c7eb8a42f..54f991b58 100644 --- a/wp/wp-content/plugins/tidb-compatibility/tidb-compatibility.php +++ b/wp/wp-content/plugins/tidb-compatibility/tidb-compatibility.php @@ -31,9 +31,18 @@ public static function wtc_init() { $wp_query->fw_clauses = $clauses; return $clauses; }, 999, 2 ); + + /** + * WP_User_Query (admin users list, etc.) + */ + add_filter( 'found_users_query', [ __CLASS__, 'wtc_add_found_users_query' ], 999, 2 ); + add_filter( 'users_pre_query', function ( $results, \WP_User_Query $query ) { + $query->query_fields = self::wtc_remove_found_rows_query( $query->query_fields ); + return $results; + }, 999, 2 ); } public static function wtc_remove_found_rows_query( $sql ) { - return str_replace( ' SQL_CALC_FOUND_ROWS ', '', $sql ); + return preg_replace( '/\bSQL_CALC_FOUND_ROWS\s+/i', '', $sql ); } public static function wtc_add_found_rows_query( $sql, WP_Query $query ) { global $wpdb; @@ -51,5 +60,15 @@ public static function wtc_add_found_rows_query( $sql, WP_Query $query ) { WHERE 1=1 $where "; } + public static function wtc_add_found_users_query( $sql, WP_User_Query $query ) { + global $wpdb; + $has_distinct = stripos( $query->query_fields, 'DISTINCT' ) !== false; + $count = $has_distinct ? "COUNT( DISTINCT {$wpdb->users}.ID )" : 'COUNT(*)'; + return " + SELECT $count + {$query->query_from} + {$query->query_where} + "; + } } WTC_FIX_WP_SLOW_QUERY::wtc_init();