-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: harmonize getRevision selector and resolver function signatures #56416
Conversation
Size Change: +49 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
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.
Thanks for following up here! This appears to resolve the issue of calling getRevision
resulting in an unnecessary API request if we already previously fetched the data as part of getRevisions
👍
An issue I ran into while testing, though, is that if I call getRevision
to grab an individual global styles revision (prior to calling getRevisions
), then the API call is still to fetch all revisions, rather than an individual one. I think the culprit might be that the following getRevisionsUrl
signature doesn't support passing in a revisionId
?
gutenberg/packages/core-data/src/entities.js
Line 214 in 8eb63dd
getRevisionsUrl: ( parentId ) => |
Example call:
wp.data.select( 'core' ).getRevision( 'root', 'globalStyles', 4169, 4180 );
This winds up calling to get all revisions for 4169
:
Updating the getRevisionsUrl
method to match what's used for postType
seems to do the trick for me:
getRevisionsUrl: ( parentId, revisionId ) =>
`/wp/v2/global-styles/${ parentId }/revisions${
revisionId ? '/' + revisionId : ''
}`,
Does that sound okay to you, or is the root
globalStyles
entity meant to behave differently to postType
?
Apologies if I'm barking up the wrong tree!
Ah yes!! Thanks for raising that. This change predates the following, recent update: Now that we support revision URLs I think we're safe to copy it over as you say.
You are too nice. This was a gross omission and deserves a proper flailing by the internet! 🤣 |
…r memoization since the function signatures are different.
…that any subsequent calls to `getRevision` for revisions that we've already fetched via `getRevisions()` are marked as resolved and therefore do not trigger the resolver (and therefore an API call).
Now that #55827 has landed we can start supporting individual global styles URLs as well.
bf78d96
to
2bb2a99
Compare
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.
This is testing great for me now, @ramonjd, thanks!
For a moment I was worried that the per_page
query param wasn't working for post revisions as I kept getting a response of only 10 revisions — then I double checked the post I was working on, and it happened to have only 10 revisions 🤦 😄
✅ getRevisions
calls for posts and global styles works as on trunk
✅ getRevision
calls for single post or single global style revisions will return the result from the resolved cache if found
✅ Using other query params still results in a fresh API call (the first time the fresh query params are used, with existing query params correctly matching a resolved response)
LGTM! ✨
Ha! Thanks a lot for testing so thoroughly. |
What?
Follow up for:
Yo!
This amazing PR:
{}
ongetRevision()
. It messes up selector memoization since the function signatures are different.getRevisions()
, the same waygetEntityRecords
does it.Why?
getRevisions()
thengetRevision()
doesn't return cached store item and replaces current items state.getRevision
for revisions that we've already fetched viagetRevisions()
are marked as resolved and therefore do not trigger the resolver (and therefore an API call).Testing Instructions
Check that the state survives multiple requests and that cached results are returned.
For example
Before
After