Add WP_User_Query support for TiDB (SQL_CALC_FOUND_ROWS / FOUND_ROWS)#133
Open
gabamnml wants to merge 1 commit into
Open
Add WP_User_Query support for TiDB (SQL_CALC_FOUND_ROWS / FOUND_ROWS)#133gabamnml wants to merge 1 commit into
gabamnml wants to merge 1 commit into
Conversation
fix to show the users list
|
@gabamnml is attempting to deploy a commit to the Mitch MacKenzie's projects Team on Vercel. A member of the Team first needs to authorize it. |
👷 Deploy request for serverlesswp pending review.Visit the deploys page to approve it
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the existing
WP_Queryworkaround to also coverWP_User_Query, which uses the same deprecated MySQL features. Without this, the WordPress admin Users screen shows correct tab counts (e.g. "All (3)") but the table displays "No users found."Problem
TiDB does not support
SQL_CALC_FOUND_ROWSorFOUND_ROWS(). WordPress admin list tables rely on these for paginated queries:wp_count_posts()WP_Querycount_users()WP_User_QueryThe plugin already patches
WP_Queryviafound_posts_query,posts_pre_query, and related filters.WP_User_Querywas not covered, so posts could display correctly while users could not.Solution
Mirror the
WP_Queryapproach forWP_User_Query:users_pre_query— StripSQL_CALC_FOUND_ROWSfrom$query->query_fieldsbefore the SELECT is built and executed.found_users_query— ReplaceSELECT FOUND_ROWS()with aCOUNT(*)(orCOUNT(DISTINCT wp_users.ID)whenDISTINCTis present) using the query's existingquery_fromandquery_whereclauses.Also harden
wtc_remove_found_rows_query()to usepreg_replaceinstead ofstr_replace, so removal works whetherSQL_CALC_FOUND_ROWSappears afterSELECTor at the start ofquery_fields.Changes
found_users_queryandusers_pre_queryfilters inwtc_init().wtc_add_found_users_query()for total user count on TiDB.wtc_remove_found_rows_query()to reliably removeSQL_CALC_FOUND_ROWSin all positions.Environment
Reproduced on WordPress 6.9.x with TiDB Cloud (MySQL-compatible protocol). Posts were fixed by activating this plugin; users remained broken until
WP_User_Querywas patched.