fix: cys intro screen parallelised network calls (#40827)
This commit is contained in:
parent
2c557f6d30
commit
a1505531bb
|
@ -18,15 +18,53 @@ export const fetchThemeCards = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchIntroData = async () => {
|
export const fetchIntroData = async () => {
|
||||||
let currentThemeIsAiGenerated = false;
|
const currentTemplatePromise =
|
||||||
const currentTemplate = await resolveSelect(
|
|
||||||
coreStore
|
|
||||||
// @ts-expect-error No types for this exist yet.
|
// @ts-expect-error No types for this exist yet.
|
||||||
).__experimentalGetTemplateForLink( '/' );
|
resolveSelect( coreStore ).__experimentalGetTemplateForLink( '/' );
|
||||||
const maybePreviousTemplate = await resolveSelect(
|
|
||||||
|
const maybePreviousTemplatePromise = resolveSelect(
|
||||||
OPTIONS_STORE_NAME
|
OPTIONS_STORE_NAME
|
||||||
).getOption( 'woocommerce_admin_customize_store_completed_theme_id' );
|
).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 (
|
if (
|
||||||
maybePreviousTemplate &&
|
maybePreviousTemplate &&
|
||||||
currentTemplate?.id === maybePreviousTemplate
|
currentTemplate?.id === maybePreviousTemplate
|
||||||
|
@ -34,33 +72,18 @@ export const fetchIntroData = async () => {
|
||||||
currentThemeIsAiGenerated = true;
|
currentThemeIsAiGenerated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const styleRevs = await resolveSelect(
|
const hasModifiedPages = rawPages?.some(
|
||||||
coreStore
|
( page: { _links: { [ key: string ]: string[] } } ) => {
|
||||||
// @ts-expect-error No types for this exist yet.
|
return page._links?.[ 'version-history' ]?.length > 1;
|
||||||
).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 activeThemeHasMods =
|
const activeThemeHasMods =
|
||||||
!! currentTemplate?.modified ||
|
!! currentTemplate?.modified ||
|
||||||
styleRevs?.length > 0 ||
|
styleRevs?.length > 0 ||
|
||||||
hasModifiedPages;
|
hasModifiedPages;
|
||||||
const customizeStoreTaskCompleted = ( await getTask( 'customize-store' ) )
|
|
||||||
?.isComplete;
|
const customizeStoreTaskCompleted = task?.isComplete;
|
||||||
const themeData = await fetchThemeCards();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeThemeHasMods,
|
activeThemeHasMods,
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Parallelised the independent network calls on the intro screen so that they become much faster
|
Loading…
Reference in New Issue