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:
Luigi Teschio 2023-11-06 11:51:11 +01:00 committed by GitHub
parent 5f819cc40e
commit cbc3bac88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 6 deletions

View File

@ -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 ) => (

View File

@ -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

View File

@ -0,0 +1,4 @@
Significance: minor
Type: performance
use multiple endpoints to improve performance