Order the core/read-users collection by display name - #948
Conversation
`core/read-users` returned collections in the `WP_User_Query` default order, which is by user login, and the output schema said nothing about it. Order by display name instead, matching what `/wp/v2/users` does, and write that order into the schema so callers can rely on it. The include list still only selects which users are returned, it does not order them.
The test counted the post meta queries that follow the request. Honoring `update_post_meta_cache` belongs to whoever runs the query, and that layer may prime more for its own reasons, so the count described the wrong thing. Check the query the ability builds instead. Verified it still fails when `should_prime_post_caches()` is gutted.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #948 +/- ##
==========================================
Coverage 73.86% 73.87%
Complexity 3032 3032
==========================================
Files 132 132
Lines 12004 12006 +2
==========================================
+ Hits 8867 8869 +2
Misses 3137 3137
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What?
Split out of #931 so it can be reviewed on its own.
Two small changes to
core/read-usersand one test change forcore/read-content:core/read-userscollections are now ordered by display name, ascending, and the output schema says so.test_include_order_does_not_control_the_result_orderexplain the new order.test_query_lean_projection_does_not_prime_the_post_meta_cachebecomestest_query_lean_projection_does_not_request_post_meta_primingand checks what the ability asks for.Why?
Collection order.
core/read-usersreturned users in whatever orderWP_User_Querypicked by default, which is by user login. The output schema documented no order at all, so a caller had no way to know what to expect, and the order could change under them. Ordering by display name matches/wp/v2/users, and it is the name a person actually sees in the response. Setting it here and writing it into the schema turns an accident into a promise.The lean projection test. The old test counted the post meta queries that ran after the request and asserted zero. That measures the wrong layer. Whether
update_post_meta_cacheis honored belongs to whoever runs the query, and that layer is free to prime more for its own reasons. What this ability owns is the request it builds, so that is what the test now checks.How?
core/read-userssetsorderby => display_nameandorder => ASCon the collection query, and theusersproperty description in the output schema gains "ordered by name, A to Z".The include list keeps working the way it did. It selects which users come back, it does not order them, which is also what the REST users controller does unless a caller asks for the include order.
test_query_lean_projection_does_not_request_post_meta_priminghookspre_get_posts, picks out the query the ability built (the one with a non-emptypost__in), and assertsupdate_post_meta_cacheis off on it.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Extracting these changes from #931, and drafting this description. Verified locally against the test suite. I reviewed and edited the result, and I take responsibility for it.
Testing Instructions
npm run wp-env:test startnpm run test:php— the full suite passes (1373 tests, 3914 assertions, 44 skipped).npm run lint:phpandnpm run lint:php:stan— both clean.To confirm the rewritten test still guards the behavior, make
Content::should_prime_post_caches()returntrueand run it again. It fails.Changelog Entry