fix: cys intro screen parallelised network calls (#40827)

This commit is contained in:
RJ 2023-10-18 18:15:36 +08:00 committed by GitHub
parent 2c557f6d30
commit a1505531bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 27 deletions

View File

@ -18,15 +18,53 @@ export const fetchThemeCards = async () => {
};
export const fetchIntroData = async () => {
let currentThemeIsAiGenerated = false;
const currentTemplate = await resolveSelect(
coreStore
const currentTemplatePromise =
// @ts-expect-error No types for this exist yet.
).__experimentalGetTemplateForLink( '/' );
const maybePreviousTemplate = await resolveSelect(
resolveSelect( coreStore ).__experimentalGetTemplateForLink( '/' );
const maybePreviousTemplatePromise = resolveSelect(
OPTIONS_STORE_NAME
).getOption( 'woocommerce_admin_customize_store_completed_theme_id' );
const styleRevsPromise =
// @ts-expect-error No types for this exist yet.
resolveSelect( coreStore ).getCurrentThemeGlobalStylesRevisions();
// @ts-expect-error No types for this exist yet.
const hasModifiedPagesPromise = resolveSelect( coreStore ).getEntityRecords(
'postType',
'page',
{
per_page: 100,
_fields: [ 'id', '_links.version-history' ],
orderby: 'menu_order',
order: 'asc',
}
);
const getTaskPromise = resolveSelect( ONBOARDING_STORE_NAME ).getTask(
'customize-store'
);
const themeDataPromise = fetchThemeCards();
const [
currentTemplate,
maybePreviousTemplate,
styleRevs,
rawPages,
task,
themeData,
] = await Promise.all( [
currentTemplatePromise,
maybePreviousTemplatePromise,
styleRevsPromise,
hasModifiedPagesPromise,
getTaskPromise,
themeDataPromise,
] );
let currentThemeIsAiGenerated = false;
if (
maybePreviousTemplate &&
currentTemplate?.id === maybePreviousTemplate
@ -34,33 +72,18 @@ export const fetchIntroData = async () => {
currentThemeIsAiGenerated = true;
}
const styleRevs = await resolveSelect(
coreStore
// @ts-expect-error No types for this exist yet.
).getCurrentThemeGlobalStylesRevisions();
const hasModifiedPages = (
await resolveSelect( coreStore )
// @ts-expect-error No types for this exist yet.
.getEntityRecords( 'postType', 'page', {
per_page: 100,
_fields: [ 'id', '_links.version-history' ],
orderby: 'menu_order',
order: 'asc',
} )
)?.some( ( page: { _links: { [ key: string ]: string[] } } ) => {
return page._links?.[ 'version-history' ]?.length > 1;
} );
const { getTask } = resolveSelect( ONBOARDING_STORE_NAME );
const hasModifiedPages = rawPages?.some(
( page: { _links: { [ key: string ]: string[] } } ) => {
return page._links?.[ 'version-history' ]?.length > 1;
}
);
const activeThemeHasMods =
!! currentTemplate?.modified ||
styleRevs?.length > 0 ||
hasModifiedPages;
const customizeStoreTaskCompleted = ( await getTask( 'customize-store' ) )
?.isComplete;
const themeData = await fetchThemeCards();
const customizeStoreTaskCompleted = task?.isComplete;
return {
activeThemeHasMods,

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Parallelised the independent network calls on the intro screen so that they become much faster