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

Enhance AI Generation time #499

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../../../../constants';

import { useSelect } from '@wordpress/data';
import { stepTheFork } from '../../../../steps/TheFork/step';
import { store as nfdOnboardingStore } from '../../../../store';
import StepNavigation from './step-navigation';

Expand Down Expand Up @@ -44,7 +45,7 @@ const SiteGenHeader = () => {
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_TOP }` }>
<>
<AdminBar />
{ isHeaderNavigationEnabled && (
{ currentStep !== stepTheFork && (
<ProgressBar progress={ progress } />
) }
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { setFlow } from '../../../utils/api/flow';
import {
generateSiteGenMeta,
getHomepages,
getSiteGenIdentifiers,
} from '../../../utils/api/siteGen';
import Footer from '../../Footer';
Expand Down Expand Up @@ -122,15 +123,33 @@
skipCache
);
if ( data !== null ) {
// A Identifier request was sucessfuly made with valid response
currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
if (
currentData.sitegen.siteGenMetaStatus.currentStatus ===
currentData.sitegen.siteGenMetaStatus.totalCount
) {
// Once all requests are completed use cache to get data
currentData.sitegen.skipCache = false;

// Increase count after site meta calls to ensure systematic call of homepages
currentData.sitegen.siteGenMetaStatus.totalCount += 1;
setCurrentOnboardingData( currentData );

// Get the homepages and set that in flow
const response = await getHomepages(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the error screen show up on the site-logo pag
also will we be calling the homepage on preview step if we already have it in the flowData ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. No error will show up on Site logo page

Screenshot 2024-03-02 at 11 44 26 AM and Hompage is just made on Exp step as we check if the flow has data before making a request in preview step it ensures the request is actually only made once however if homepage fails in exp step it is retried again in preview step where the error state is shown if it never works.

currentData.sitegen.siteDetails.prompt
);

if ( response.body ) {
currentData.sitegen.homepages.data = response.body;
}
currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
}
// Sync the current request changed to State
setCurrentOnboardingData( currentData );

// Sets the Site Title and Taglin in Live Preview
if ( identifier === 'site_config' ) {
editEntityRecord( 'root', 'site', undefined, {
title: data.site_title,
Expand All @@ -139,6 +158,7 @@
}
}
} catch ( err ) {
// Check if it failed then retry again
if ( retryCount < MAX_RETRIES_SITE_GEN ) {
return performSiteGenMetaGeneration(
siteInfo,
Expand All @@ -148,20 +168,34 @@
);
}

// If the retry also did not work show the error state
setFailedApi( ( prevState ) => {
// If the error doesn't exist add it to the Failed List
if ( ! prevState.includes( identifier ) ) {
return [ ...prevState, identifier ];
}
return prevState;
} );
// Activate the Error Page
currentData.sitegen.siteGenErrorStatus = true;
setCurrentOnboardingData( currentData );
}
}

async function generateSiteGenData() {
async function generateSiteGenData( forceRun = false ) {
// ForceRun tells us to bypass the page check or not
// because the requests failed on Logo step is retried in Experience step

// Start the API Requests when the loader is shown.
if ( ! location.pathname.includes( 'experience' ) ) {
if ( ! location.pathname.includes( 'site-logo' ) && ! forceRun ) {
return;
}

// If all the requests have been made already skip this
if (
currentData.sitegen.siteGenMetaStatus.currentStatus ===
currentData.sitegen.siteGenMetaStatus.totalCount
) {
return;
}

Expand All @@ -181,9 +215,9 @@
identifiers = identifiers.body;

currentData.sitegen.siteGenMetaStatus.currentStatus = 0;

setCurrentOnboardingData( currentData );
}

const siteInfo = {
site_description: currentData.sitegen?.siteDetails?.prompt,
};
Expand Down Expand Up @@ -258,38 +292,38 @@

useEffect( () => {
trackChapters();
}, [ currentStep ] );

Check warning on line 295 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

useEffect( () => {
if ( initialize ) {
initializePlugins( pluginInstallHash );
setInterval( cronTrigger, 45000 );
}
}, [ initialize ] );

Check warning on line 302 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

useEffect( () => {
syncStoreToDB();
generateSiteGenData();
handlePreviousStepTracking();
}, [ location.pathname ] );

Check warning on line 308 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

useEffect( () => {
if (
prevSiteGenErrorStatus.current === true &&
siteGenErrorStatus === false
) {
generateSiteGenData();
generateSiteGenData( true );
syncStoreToDB();
}
prevSiteGenErrorStatus.current = siteGenErrorStatus;
}, [ siteGenErrorStatus ] );

Check warning on line 319 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData' and 'syncStoreToDB'. Either include them or remove the dependency array

useEffect( () => {
initializeThemes();
initializeSettings();
getEditedEntityRecord( 'root', 'site' );
updateSiteGenErrorStatus( false );
}, [] );

Check warning on line 326 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'getEditedEntityRecord' and 'updateSiteGenErrorStatus'. Either include them or remove the dependency array

return (
<ThemeProvider>
Expand Down
79 changes: 38 additions & 41 deletions src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import CommonLayout from '../../../components/Layouts/Common';
import NextButtonSiteGen from '../../../components/Button/NextButtonSiteGen';
import ImageUploaderWithText from '../../../components/ImageUploader/components/ImageUploaderWithText';
import SitegenAiStateHandler from '../../../components/StateHandlers/SitegenAi';
import {
OnboardingEvent,
trackOnboardingEvent,
Expand Down Expand Up @@ -81,7 +80,7 @@
}
setIsFooterNavAllowed( false );
getEditedEntityRecord( 'root', 'site' );
}, [] );

Check warning on line 83 in src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'currentData.sitegen.siteLogo', 'getEditedEntityRecord', 'setDrawerActiveView', 'setHeaderActiveView', 'setHideFooterNav', 'setIsFooterNavAllowed', 'setIsHeaderEnabled', 'setIsHeaderNavigationEnabled', and 'setSidebarActiveView'. Either include them or remove the dependency array

const handleSiteLogo = ( siteLogoNew ) => {
const currentDataCopy = { ...currentData };
Expand All @@ -99,49 +98,47 @@

const content = getContents();
return (
<SitegenAiStateHandler>
<CommonLayout
isCentered
className="nfd-onboarding-step--site-gen__site-logo"
>
<div className="nfd-onboarding-step--site-gen__site-logo__container">
<AIHeading title={ content.heading } />
<ImageUploaderWithText
image={ siteLogo }
imageSetter={ handleSiteLogo }
<CommonLayout
isCentered
className="nfd-onboarding-step--site-gen__site-logo"
>
<div className="nfd-onboarding-step--site-gen__site-logo__container">
<AIHeading title={ content.heading } />
<ImageUploaderWithText
image={ siteLogo }
imageSetter={ handleSiteLogo }
/>
<div className="nfd-onboarding-step--site-gen__site-logo__container__buttons">
<SkipButton
callback={ () => resetSiteLogo() }
className="nfd-onboarding-step--site-gen__site-logo__container__buttons__skip"
text={ content.buttons.skip }
/>
<div className="nfd-onboarding-step--site-gen__site-logo__container__buttons">
<SkipButton
callback={ () => resetSiteLogo() }
className="nfd-onboarding-step--site-gen__site-logo__container__buttons__skip"
text={ content.buttons.skip }
/>
{ isLargeViewport && (
<NextButtonSiteGen
callback={ () => {
if ( siteLogo ) {
trackOnboardingEvent(
new OnboardingEvent(
ACTION_LOGO_ADDED
),
{
source: SITEGEN_FLOW,
}
);
}
} }
text={ content.buttons.next }
disabled={
siteLogo === undefined || siteLogo?.id === 0
? true
: false
{ isLargeViewport && (
<NextButtonSiteGen
callback={ () => {
if ( siteLogo ) {
trackOnboardingEvent(
new OnboardingEvent(
ACTION_LOGO_ADDED
),
{
source: SITEGEN_FLOW,
}
);
}
/>
) }
</div>
} }
text={ content.buttons.next }
disabled={
siteLogo === undefined || siteLogo?.id === 0
? true
: false
}
/>
) }
</div>
</CommonLayout>
</SitegenAiStateHandler>
</div>
</CommonLayout>
);
};

Expand Down
Loading