feat(MED-98): load packages page slightly faster

This commit is contained in:
Karli
2025-09-30 16:22:10 +03:00
parent 2af0ad4d15
commit 176e1e2a3c

View File

@@ -3,7 +3,7 @@ import { cache } from 'react';
import { getAnalysisElementMedusaProductIds } from '@/utils/medusa-product';
import { listProductTypes, listProducts } from '@lib/data/products';
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 { AnalysisPackageWithVariant } from '@kit/shared/components/select-analysis-package';
@@ -118,17 +118,12 @@ async function analysisPackageElementsLoader({
async function analysisPackagesWithVariantLoader({
account,
countryCode,
productType,
}: {
account: AccountWithParams;
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({
countryCode,
queryParams: { limit: 100, 'type_id[0]': productType.id },
@@ -171,12 +166,23 @@ async function analysisPackagesLoader() {
throw new Error('Account not found');
}
const countryCodes = await loadCountryCodes();
const [countryCodes, productTypes] = await Promise.all([
loadCountryCodes(),
loadProductTypes(),
]);
const countryCode = countryCodes[0]!;
const productType = productTypes.find(
({ metadata }) => metadata?.handle === 'analysis-packages',
);
if (!productType) {
return { analysisPackageElements: [], analysisPackages: [], countryCode };
}
const analysisPackagesWithVariant = await analysisPackagesWithVariantLoader({
account,
countryCode,
productType,
});
if (!analysisPackagesWithVariant) {
return { analysisPackageElements: [], analysisPackages: [], countryCode };