From db19a84080db7421dca1039d7ca27db93a0cddc6 Mon Sep 17 00:00:00 2001 From: Bryann Yeap Kok Keong Date: Tue, 25 Oct 2022 10:40:55 +0800 Subject: [PATCH] [offers][chore] Speed up fetching of dashboard offers --- .../portal/src/server/router/offers/offers.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/portal/src/server/router/offers/offers.ts b/apps/portal/src/server/router/offers/offers.ts index 84756179..7d5ff908 100644 --- a/apps/portal/src/server/router/offers/offers.ts +++ b/apps/portal/src/server/router/offers/offers.ts @@ -73,7 +73,7 @@ export const offersRouter = createRouter().query('list', { const order = getOrder(input.sortBy.charAt(0)); const sortingKey = input.sortBy.substring(1); - let data = !yoeRange + const data = !yoeRange ? await ctx.prisma.offersOffer.findMany({ // Internship include: { @@ -303,11 +303,18 @@ export const offersRouter = createRouter().query('list', { }, }); + const startRecordIndex: number = input.limit * input.offset; + const endRecordIndex: number = + startRecordIndex + input.limit <= data.length + ? startRecordIndex + input.limit + : data.length; + let paginatedData = data.slice(startRecordIndex, endRecordIndex); + // CONVERTING const currency = input.currency?.toUpperCase(); if (currency != null && currency in Currency) { - data = await Promise.all( - data.map(async (offer) => { + paginatedData = await Promise.all( + paginatedData.map(async (offer) => { if (offer.offersFullTime?.totalCompensation != null) { offer.offersFullTime.totalCompensation.value = await convertWithDate( @@ -367,13 +374,6 @@ export const offersRouter = createRouter().query('list', { ); } - const startRecordIndex: number = input.limit * input.offset; - const endRecordIndex: number = - startRecordIndex + input.limit <= data.length - ? startRecordIndex + input.limit - : data.length; - const paginatedData = data.slice(startRecordIndex, endRecordIndex); - return getOffersResponseMapper( paginatedData.map((offer) => dashboardOfferDtoMapper(offer)), {