Skip to content

Commit

Permalink
Fix asset store display speed and reduce the burst of requests (#7241)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSi authored Dec 17, 2024
1 parent c9e5272 commit 44daf70
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
6 changes: 5 additions & 1 deletion newIDE/app/src/AssetStore/AssetCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export const AssetCard = ({
<div id={id} style={{ ...styles.cardContainer, width: size, height: size }}>
<div style={{ ...styles.previewContainer, width: size, height: size }}>
<CheckeredBackground />
<AssetPreviewImage assetShortHeader={assetShortHeader} maxSize={128} />
<AssetPreviewImage
assetShortHeader={assetShortHeader}
maxSize={128}
loading="lazy"
/>
</div>
<div
style={{
Expand Down
9 changes: 8 additions & 1 deletion newIDE/app/src/AssetStore/AssetPreviewImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ const styles = {
type Props = {|
assetShortHeader: AssetShortHeader,
maxSize?: number,
loading?: 'lazy',
|};

export const AssetPreviewImage = ({ assetShortHeader, maxSize }: Props) => {
export const AssetPreviewImage = ({
assetShortHeader,
maxSize,
loading,
}: Props) => {
const previewImageUrl = assetShortHeader.previewImageUrls[0];
const isPrivate = isPrivateAsset(assetShortHeader);
const [isLoaded, setIsLoaded] = React.useState(false);
Expand All @@ -55,6 +60,7 @@ export const AssetPreviewImage = ({ assetShortHeader, maxSize }: Props) => {
url={previewImageUrl}
alt={assetShortHeader.name}
onLoad={onLoad}
loading={loading}
/>
) : (
<CorsAwareImage
Expand All @@ -63,6 +69,7 @@ export const AssetPreviewImage = ({ assetShortHeader, maxSize }: Props) => {
src={previewImageUrl}
alt={assetShortHeader.name}
onLoad={onLoad}
loading={loading}
/>
);
};
10 changes: 6 additions & 4 deletions newIDE/app/src/AssetStore/AssetsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import HelpIcon from '../UI/HelpIcon';
import { OwnedProductLicense } from './ProductLicense/ProductLicenseOptions';
import { getUserProductPurchaseUsageType } from './ProductPageHelper';

const ASSETS_DISPLAY_LIMIT = 250;
const ASSETS_DISPLAY_LIMIT = 60;

const getAssetSize = (windowSize: WindowSizeType) => {
switch (windowSize) {
Expand Down Expand Up @@ -338,7 +338,7 @@ const AssetsList = React.forwardRef<Props, AssetsListInterface>(
scrollViewElement.scrollToPosition(y);
},
setPageBreakIndex: (index: number) => {
setPageBreakIndex(0);
setPageBreakIndex(index);
},
}));

Expand Down Expand Up @@ -471,6 +471,8 @@ const AssetsList = React.forwardRef<Props, AssetsListInterface>(
if (!assetShortHeaders) return null;
// Don't show assets if filtering on asset packs.)
if (hasAssetPackFiltersApplied && !openedAssetPack) return [];
const assetSize = getAssetSize(windowSize);
const margin = cellSpacing / 2;

return getAssetShortHeadersToDisplay(
assetShortHeaders,
Expand All @@ -480,9 +482,9 @@ const AssetsList = React.forwardRef<Props, AssetsListInterface>(
<AssetCardTile
assetShortHeader={assetShortHeader}
onOpenDetails={() => onOpenDetails(assetShortHeader)}
size={getAssetSize(windowSize)}
size={assetSize}
key={assetShortHeader.id}
margin={cellSpacing / 2}
margin={margin}
hideShortDescription={!!hideDetails}
/>
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Props = {|
onError?: () => void,
onLoad?: (e: any) => void,
hideLoader?: boolean,
loading?: 'lazy',
|};

const AuthorizedAssetImage = ({
Expand All @@ -20,6 +21,7 @@ const AuthorizedAssetImage = ({
onError,
onLoad,
hideLoader,
loading,
}: Props) => {
const [authorizedUrl, setAuthorizedUrl] = React.useState(null);
const [isImageLoaded, setIsImageLoaded] = React.useState(false);
Expand Down Expand Up @@ -78,6 +80,7 @@ const AuthorizedAssetImage = ({
<img
alt={alt}
src={authorizedUrl}
loading={loading}
style={{
...style,
// Use display none to load the image in the background, but not
Expand Down
6 changes: 6 additions & 0 deletions newIDE/app/src/AssetStore/ShopTiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export const PublicAssetPackTile = ({
style={styles.previewImage}
src={assetPack.thumbnailUrl}
alt={`Preview image of asset pack ${assetPack.name}`}
loading="lazy"
/>
<Column>
<Line justifyContent="space-between" noMargin>
Expand Down Expand Up @@ -299,6 +300,7 @@ export const PrivateAssetPackTile = ({
style={styles.previewImage}
src={assetPackListingData.thumbnailUrls[0]}
alt={`Preview image of asset pack ${assetPackListingData.name}`}
loading="lazy"
/>
{assetPackListingData.redeemConditions && !owned && (
<div style={styles.redeemableContainer}>
Expand Down Expand Up @@ -367,6 +369,7 @@ export const PromoBundleCard = ({
}}
src={productListingData.thumbnailUrls[0]}
alt={`Preview image of bundle ${productListingData.name}`}
loading="lazy"
/>
</div>
<Column expand alignItems="flex-start" justifyContent="center">
Expand Down Expand Up @@ -476,6 +479,7 @@ export const CategoryTile = ({
}}
src={imageSource}
alt={imageAlt}
// No lazy loading because categories are the first seen tiles in the shop.
/>
<Column>
<Line justifyContent="center" noMargin>
Expand Down Expand Up @@ -527,6 +531,7 @@ export const PrivateGameTemplateTile = ({
alt={`Preview image of game template ${
privateGameTemplateListingData.name
}`}
loading="lazy"
/>
<div style={styles.priceTagContainer}>
<ProductPriceTag
Expand Down Expand Up @@ -603,6 +608,7 @@ export const ExampleTile = ({
style={styles.previewImage}
src={thumbnailImgUrl}
alt={`Preview image of example ${exampleShortHeader.name}`}
loading="lazy"
/>
) : (
<EmptyMessage
Expand Down
4 changes: 2 additions & 2 deletions newIDE/app/src/AssetStore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,11 @@ export const AssetStore = React.forwardRef<Props, AssetStoreInterface>(
<Column expand useFullHeight noMargin>
<SearchBar
placeholder={
hideGameTemplates ? t`Search assets` : `Search the shop`
hideGameTemplates ? t`Search assets` : t`Search the shop`
}
value={searchText}
onChange={(newValue: string) => {
if (searchText === newValue) {
if (searchText === newValue || newValue.length === 1) {
return;
}
setSearchText(newValue);
Expand Down
1 change: 1 addition & 0 deletions newIDE/app/src/UI/CorsAwareImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Props = {|
title?: ?string,
onError?: (?Error) => void,
onLoad?: (e: any) => void,
loading?: 'lazy',
|};

const addSearchParameterToUrl = (
Expand Down
4 changes: 2 additions & 2 deletions newIDE/app/src/UI/Search/UseSearchItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ export const useSearchItem = <SearchItem: SearchableItem>(
[searchItemsById, getItemDescription]
);

// Update the search results according to the items, search term
// chosen category and chosen filters.
const searchApi = searchApiRef.current;
React.useEffect(
() => {
Expand Down Expand Up @@ -351,6 +349,8 @@ export const useSearchItem = <SearchItem: SearchableItem>(
discardSearch = true;
};
},
// Update the search results according to the items, search term
// chosen category and chosen filters.
[
shuffledSearchItems,
sortedSearchItems,
Expand Down

0 comments on commit 44daf70

Please sign in to comment.