Fix pattern route performance (#41168)
* fix pattern route performance * Fetch multiple endpoints * update namespace * update business description * fix payload * remove eslint comment * add changelog * update interval of the loading frames
This commit is contained in:
parent
5f819cc40e
commit
cbc3bac88c
|
@ -116,8 +116,7 @@ export const ApiCallLoader = () => {
|
|||
return (
|
||||
<Loader>
|
||||
<Loader.Sequence
|
||||
/* divide all frames equally over 1m. */
|
||||
interval={ ( 60 * 1000 ) / ( loaderSteps.length - 1 ) }
|
||||
interval={ ( 40 * 1000 ) / ( loaderSteps.length - 1 ) }
|
||||
shouldLoop={ false }
|
||||
>
|
||||
{ loaderSteps.slice( 0, -1 ).map( ( step, index ) => (
|
||||
|
|
|
@ -218,11 +218,11 @@ export const updateStorePatterns = async (
|
|||
woocommerce_blocks_allow_ai_connection: true,
|
||||
} );
|
||||
|
||||
const response: {
|
||||
const { images } = await apiFetch< {
|
||||
ai_content_generated: boolean;
|
||||
additional_errors?: unknown[];
|
||||
} = await apiFetch( {
|
||||
path: '/wc/store/patterns',
|
||||
images: Array< unknown >;
|
||||
} >( {
|
||||
path: '/wc/private/ai/images',
|
||||
method: 'POST',
|
||||
data: {
|
||||
business_description:
|
||||
|
@ -230,6 +230,63 @@ export const updateStorePatterns = async (
|
|||
},
|
||||
} );
|
||||
|
||||
const [ response ] = await Promise.all< {
|
||||
ai_content_generated: boolean;
|
||||
product_content: Array< {
|
||||
title: string;
|
||||
description: string;
|
||||
image: {
|
||||
src: string;
|
||||
alt: string;
|
||||
};
|
||||
} >;
|
||||
additional_errors?: unknown[];
|
||||
} >( [
|
||||
apiFetch( {
|
||||
path: '/wc/private/ai/products',
|
||||
method: 'POST',
|
||||
data: {
|
||||
business_description:
|
||||
context.businessInfoDescription.descriptionText,
|
||||
images,
|
||||
},
|
||||
} ),
|
||||
apiFetch( {
|
||||
path: '/wc/private/ai/patterns',
|
||||
method: 'POST',
|
||||
data: {
|
||||
business_description:
|
||||
context.businessInfoDescription.descriptionText,
|
||||
images,
|
||||
},
|
||||
} ),
|
||||
] );
|
||||
|
||||
const productContents = response.product_content.map(
|
||||
( product, index ) => {
|
||||
return apiFetch( {
|
||||
path: '/wc/private/ai/product',
|
||||
method: 'POST',
|
||||
data: {
|
||||
products_information: product,
|
||||
index,
|
||||
},
|
||||
} );
|
||||
}
|
||||
);
|
||||
|
||||
await Promise.all( [
|
||||
...productContents,
|
||||
apiFetch( {
|
||||
path: '/wc/private/ai/business-description',
|
||||
method: 'POST',
|
||||
data: {
|
||||
business_description:
|
||||
context.businessInfoDescription.descriptionText,
|
||||
},
|
||||
} ),
|
||||
] );
|
||||
|
||||
if ( ! response.ai_content_generated ) {
|
||||
throw new Error(
|
||||
'AI content not generated: ' + response.additional_errors
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: performance
|
||||
|
||||
use multiple endpoints to improve performance
|
Loading…
Reference in New Issue