-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Core Data: Include pagination meta while receiving intermediate results #71401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core Data: Include pagination meta while receiving intermediate results #71401
Conversation
|
Size Change: +2 B (0%) Total Size: 1.92 MB
ℹ️ View Unchanged
|
| totalItems: parseInt( | ||
| response.headers.get( 'X-WP-Total' ) | ||
| ), | ||
| totalPages: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be using X-WP-TotalPages? We could use the totalPages constant from above:
| totalPages: 1, | |
| totalPages, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The total pages definition above is used for the loop. The number of pages for unbound queries should be one, as it fetches all results and technically isn't "paginated".
From previous work - #64772.
gutenberg/packages/core-data/src/resolvers.js
Lines 332 to 335 in b5d6d76
| meta = { | |
| totalItems: records.length, | |
| totalPages: 1, | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
|
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. |
tyxla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Would be interesting to see a unit test for this one, but I can imagine it being a bit tricky to set up.
Yes, it's tricky to do as an actual unit test; we'll have to mock a lot of things, and then the value won't be the same. It has been mentioned a couple of times, but to thoroughly test code data selectors, we need integration tests that mock the API responses. There are a couple of other Core Data issues I plan to address, so I might try to implement integration tests first to avoid accidental regressions. P.S. Failing e2e tests aren't related. I'm going to merge this. |
What?
This is a follow-up to #66713.
PR updates
getEntityRecordsresolver to include pagination meta while store receives intermediate results.Why?
The
X-WP-Totalheader is available in this case, so there's no need to wait for full resolution to derive and send total items data.It's helpful when an app displays a loading state that uses the currently fetched records and the total number of expected items.
Testing Instructions
This is a bit hard to test manually, so confirm that the changed logic has its merit 😓