-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Mark 'canUser' related actions resolvers as resolved #63435
Conversation
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. |
Size Change: -9 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
|
||
// Mark related action resolutions as finished. | ||
if ( action !== requestedAction ) { | ||
dispatch.finishResolution( 'canUser', [ |
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.
If two useSelect calls try to retrieve two different actions before the resolution, we'll still be triggering two API requests.
A better approach might be to separate this resolver into a sub selector/resolver no?
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.
So you're saying, in some scenarios, this could invalidate the existing check at the top?
gutenberg/packages/core-data/src/resolvers.js
Lines 397 to 410 in da558e2
// Prevent resolving the same resource twice. | |
for ( const relatedAction of retrievedActions ) { | |
if ( relatedAction === requestedAction ) { | |
continue; | |
} | |
const isAlreadyResolving = hasStartedResolution( 'canUser', [ | |
relatedAction, | |
resource, | |
id, | |
] ); | |
if ( isAlreadyResolving ) { | |
return; | |
} | |
} |
A better approach might be to separate this resolver into a sub selector/resolver no?
Do you have an example?
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.
No, actually I missed that check and you're right, we seem covered already.
That said, I think we can avoid all of that (both marking as resolved and the check to avoid starting the resolution) by relying on a shared sub resolver/selector.
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.
That said, I think we can avoid all of that (both marking as resolved and the check to avoid starting the resolution) by relying on a shared sub resolver/selector.
Making a note and happy to follow up on this as "polish step". While I think I have an idea of what you mean by shared sub-resolver/selector. Do you mind sharing an example so we're on the same page 😅
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.
Something like:
export const canUser =
( requestedAction, resource, id ) => async ( { resolveSelect } ) => {
await resolveSelect.getResourcePermissions( resource, id );
}
Thanks, @youknowriad! |
…Press#63435) Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
What?
See #63430 (comment).
PR updates the
canUser
resolver to mark related actions as resolved when their store records are populated.Testing Instructions
wp.data.select( 'core' ).canUser( 'update', { kind: 'root', name: 'media', id: 1342 } );
.wp.data.select( 'core' ).hasFinishedResolution( 'canUser', [ 'read', { kind: 'root', name: 'media', id: 1342 } ] );
Testing Instructions for Keyboard
Same.