Opened 5 years ago
Last modified 11 days ago
#54378 new enhancement
Admin Pages - The dropdown of 'Main Page (no parent)' on QuickEdit query is slow
| Reported by: | activecoder | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Quick/Bulk Edit | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | administration, performance |
Description
Hi, It seems like the file "wordpress/wp-admin/includes/class-wp-posts-list-table.php", line "wp_dropdown_pages( $dropdown_args );" that used to display the QuickEdit dropdown for 'Main Page (no parent)' is triggering a SQL query on all columns of the wp_posts table for all top level pages. This cause a very slow query if the system has lots of top level pages. Should WP use a more optimize query for this dropdown list that only going to display the Page title?
The query used for the drop down is:
SELECT *
FROM wp_posts
WHERE (post_type = 'page'
AND post_status = 'publish')
ORDER BY menu_order,wp_posts.post_title ASC
Change History (7)
#4
@
4 years ago
This was reviewed in the weekly focus on component tickets this week. This could be an improvement if there is a contributor(s) who is able to work on this. @activecoder is this something you would like to work on and do you have any examples to help others with understanding the extent of this being an issue? Thank you for raising the question and for your first ticket in Trac.
This ticket was mentioned in Slack in #core by abhanonstopnews. View the logs.
4 years ago
#6
@
2 years ago
Just checking in @activecoder if there is anything new you would like to add to this ticket, or if you have any more detail from a recent work through of the steps you listed above. Thanks.
This ticket was mentioned in PR #15499 on WordPress/wordpress-develop by @jdeep.
11 days ago
#7
- Keywords has-patch has-unit-tests added
The Quick Edit and Bulk Edit parent drop-down on the Pages screen calls get_pages(), which runs SELECT wp_posts.* for every published page on every load of the screen. The drop-down only needs a few fields, but the query also loads post_content and the other long text columns. On sites with many or large pages this is slow and uses a lot of memory.
WP_Query has no way to select specific columns, so this PR adds one and uses it for the drop-down.
Changes
WP_Query: thefieldsargument now also accepts an array of post field names.- Only those fields and
IDare selected. Unknown names are ignored, so arbitrary input never reaches the SQL. - The result is an array of partial
WP_Postobjects. Fields that weren't selected are empty. - Partial objects are not added to the post cache. The query cache already skips non-standard field sets.
- The loop still sets up full posts:
the_post()already loads the full post wheneverfieldsisn't'all'.
- Only those fields and
get_pages(): new optionalfieldsargument, passed toWP_Query.post_parent,post_typeandpost_statusare always loaded, so hierarchy and functions likeget_permalink()keep working. It isn't added to the defaults, so the parsed arguments are unchanged for existing callers.wp_dropdown_pages(): adds itsvalue_fieldtofieldswhenfieldsis given.- Quick Edit parent drop-down: loads every field except
post_content,post_excerpt,post_content_filtered,to_pingandpinged.
Code that doesn't pass fields as an array behaves exactly as before, including caching.
Performance
The drop-down query itself:
| Pages × content | Trunk (1 × SELECT *) | Current Changeset | Data returned |
|---|---|---|---|
| 500 × 10 KB | 4.5 ms | 2.5 ms | 5.24 MB → 0.30 MB |
| 2,000 × 10 KB | 20.6 ms | 10.0 ms | 20.97 MB → 1.22 MB |
| 5,000 × 10 KB | 47.8 ms | 23.5 ms | 52.43 MB → 3.05 MB |
| 2,000 × 50 KB | 81.2 ms | 8.7 ms | 99.11 MB → 1.22 MB |
WP_Posts_List_Table::inline_edit():
| Pages | Peak memory | Pages written to the post cache |
|---|---|---|
| 500 | 15.1 MB → 3.1 MB | 400 → 0 |
| 2,000 | 60.4 MB → 7.0 MB | 1,600 → 0 |
| 5,000 | 151.3 MB → 14.8 MB | 4,000 → 0 |
The drop-down HTML is identical to trunk at every size. Total inline_edit() time is about the same, since building the <option> markup dominates.
In the Quick Edit and Bulk Edit parent drop-down only, get_pages / list_pages callbacks receive WP_Post objects with empty post_content, post_excerpt, post_content_filtered, to_ping and pinged. Plugins that need them can remove fields via the quick_edit_dropdown_pages_args filter.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Reproducing the issue, drafting the patch and tests. I reviewed, tested and edited the final implementation, tests and benchmarks.
This was reviewed in the weekly focus on component tickets this week. This could be an improvement if there is a contributor(s) who is able to work on this. @activecoder is this something you would like to work on and do you have any examples to help others with understanding the extent of this being an issue? Thank you for raising the question and for your first ticket in Trac.