Skip to content
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: Batch remaining actions in resolvers #65176

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 37 additions & 29 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ export const getUserPatternCategories =

export const getNavigationFallbackId =
() =>
async ( { dispatch, select } ) => {
async ( { dispatch, select, registry } ) => {
const fallback = await apiFetch( {
path: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', {
_embed: true,
Expand All @@ -764,9 +764,13 @@ export const getNavigationFallbackId =

const record = fallback?._embedded?.self;

dispatch.receiveNavigationFallbackId( fallback?.id );
registry.batch( () => {
dispatch.receiveNavigationFallbackId( fallback?.id );

if ( ! record ) {
getdave marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if ( record ) {
// If the fallback is already in the store, don't invalidate navigation queries.
// Otherwise, invalidate the cache for the scenario where there were no Navigation
// posts in the state and the fallback created one.
Expand All @@ -790,7 +794,7 @@ export const getNavigationFallbackId =
'wp_navigation',
fallback.id,
] );
}
} );
};

export const getDefaultTemplateId =
Expand All @@ -817,7 +821,7 @@ export const getDefaultTemplateId =
*/
export const getRevisions =
( kind, name, recordKey, query = {} ) =>
async ( { dispatch } ) => {
async ( { dispatch, registry } ) => {
const configs = await dispatch( getOrLoadEntitiesConfig( kind, name ) );
const entityConfig = configs.find(
( config ) => config.name === name && config.kind === kind
Expand Down Expand Up @@ -884,32 +888,36 @@ export const getRevisions =
} );
}

dispatch.receiveRevisions(
kind,
name,
recordKey,
records,
query,
false,
meta
);
registry.batch( () => {
dispatch.receiveRevisions(
kind,
name,
recordKey,
records,
query,
false,
meta
);

// When requesting all fields, the list of results can be used to
// resolve the `getRevision` selector in addition to `getRevisions`.
if ( ! query?._fields && ! query.context ) {
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
const resolutionsArgs = records
.filter( ( record ) => record[ key ] )
.map( ( record ) => [
kind,
name,
recordKey,
record[ key ],
] );
// When requesting all fields, the list of results can be used to
// resolve the `getRevision` selector in addition to `getRevisions`.
if ( ! query?._fields && ! query.context ) {
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
const resolutionsArgs = records
.filter( ( record ) => record[ key ] )
.map( ( record ) => [
kind,
name,
recordKey,
record[ key ],
] );

dispatch.startResolutions( 'getRevision', resolutionsArgs );
getdave marked this conversation as resolved.
Show resolved Hide resolved
dispatch.finishResolutions( 'getRevision', resolutionsArgs );
}
dispatch.finishResolutions(
'getRevision',
resolutionsArgs
);
}
} );
}
};

Expand Down
Loading