feat(MED-98): load packages page slightly faster
This commit is contained in:
@@ -3,7 +3,7 @@ import { cache } from 'react';
|
|||||||
import { getAnalysisElementMedusaProductIds } from '@/utils/medusa-product';
|
import { getAnalysisElementMedusaProductIds } from '@/utils/medusa-product';
|
||||||
import { listProductTypes, listProducts } from '@lib/data/products';
|
import { listProductTypes, listProducts } from '@lib/data/products';
|
||||||
import { listRegions } from '@lib/data/regions';
|
import { listRegions } from '@lib/data/regions';
|
||||||
import type { StoreProduct } from '@medusajs/types';
|
import type { StoreProduct, StoreProductType } from '@medusajs/types';
|
||||||
|
|
||||||
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
import type { AccountWithParams } from '@kit/accounts/types/accounts';
|
||||||
import type { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
|
import type { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
|
||||||
@@ -118,17 +118,12 @@ async function analysisPackageElementsLoader({
|
|||||||
async function analysisPackagesWithVariantLoader({
|
async function analysisPackagesWithVariantLoader({
|
||||||
account,
|
account,
|
||||||
countryCode,
|
countryCode,
|
||||||
|
productType,
|
||||||
}: {
|
}: {
|
||||||
account: AccountWithParams;
|
account: AccountWithParams;
|
||||||
countryCode: string;
|
countryCode: string;
|
||||||
|
productType: StoreProductType;
|
||||||
}) {
|
}) {
|
||||||
const productTypes = await loadProductTypes();
|
|
||||||
const productType = productTypes.find(
|
|
||||||
({ metadata }) => metadata?.handle === 'analysis-packages',
|
|
||||||
);
|
|
||||||
if (!productType) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const analysisPackagesResponse = await listProducts({
|
const analysisPackagesResponse = await listProducts({
|
||||||
countryCode,
|
countryCode,
|
||||||
queryParams: { limit: 100, 'type_id[0]': productType.id },
|
queryParams: { limit: 100, 'type_id[0]': productType.id },
|
||||||
@@ -171,12 +166,23 @@ async function analysisPackagesLoader() {
|
|||||||
throw new Error('Account not found');
|
throw new Error('Account not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const countryCodes = await loadCountryCodes();
|
const [countryCodes, productTypes] = await Promise.all([
|
||||||
|
loadCountryCodes(),
|
||||||
|
loadProductTypes(),
|
||||||
|
]);
|
||||||
const countryCode = countryCodes[0]!;
|
const countryCode = countryCodes[0]!;
|
||||||
|
const productType = productTypes.find(
|
||||||
|
({ metadata }) => metadata?.handle === 'analysis-packages',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!productType) {
|
||||||
|
return { analysisPackageElements: [], analysisPackages: [], countryCode };
|
||||||
|
}
|
||||||
|
|
||||||
const analysisPackagesWithVariant = await analysisPackagesWithVariantLoader({
|
const analysisPackagesWithVariant = await analysisPackagesWithVariantLoader({
|
||||||
account,
|
account,
|
||||||
countryCode,
|
countryCode,
|
||||||
|
productType,
|
||||||
});
|
});
|
||||||
if (!analysisPackagesWithVariant) {
|
if (!analysisPackagesWithVariant) {
|
||||||
return { analysisPackageElements: [], analysisPackages: [], countryCode };
|
return { analysisPackageElements: [], analysisPackages: [], countryCode };
|
||||||
|
|||||||
Reference in New Issue
Block a user