diff --git a/backend/src/cron/cron.service.ts b/backend/src/cron/cron.service.ts index c1c3d0e..b855311 100644 --- a/backend/src/cron/cron.service.ts +++ b/backend/src/cron/cron.service.ts @@ -15,6 +15,7 @@ import Redis from 'ioredis'; import { InjectRedis } from '@songkeys/nestjs-redis'; import { getProductInfo } from 'src/utils/product.info'; import { CacheService } from 'src/cache/cache.service'; +import { RecentProductInfoMap } from 'src/types/product'; @Injectable() export class CronService { @@ -70,10 +71,18 @@ export class CronService { } } + const recentProductInfoMap: RecentProductInfoMap = recentProductInfo.reduce((map, product) => { + map[product.productId] = { productName: product.productName, imageUrl: product.imageUrl }; + return map; + }, {} as RecentProductInfoMap); + totalProducts.sort((a, b) => a.id.localeCompare(b.id)); - recentProductInfo.sort((a, b) => a.productId.localeCompare(b.productId)); - const infoUpdatedProducts = totalProducts.filter((product, idx) => { - const recentInfo = recentProductInfo[idx]; + const infoUpdatedProducts = totalProducts.filter((product) => { + const recentInfo = recentProductInfoMap[product.id]; + if (recentInfo === undefined) { + console.log('fail', product.productCode); + return false; + } if (product.productName !== recentInfo.productName || product.imageUrl !== recentInfo.imageUrl) { product.productName = recentInfo.productName; product.imageUrl = recentInfo.imageUrl; diff --git a/backend/src/types/product.ts b/backend/src/types/product.ts new file mode 100644 index 0000000..0604a71 --- /dev/null +++ b/backend/src/types/product.ts @@ -0,0 +1,6 @@ +export type RecentProductInfoMap = { + [key: string]: { + productName: string; + imageUrl: string; + }; +};