mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 04:33:42 +08:00
[offers][chore] Speed up fetching of dashboard offers
This commit is contained in:
@ -73,7 +73,7 @@ export const offersRouter = createRouter().query('list', {
|
|||||||
const order = getOrder(input.sortBy.charAt(0));
|
const order = getOrder(input.sortBy.charAt(0));
|
||||||
const sortingKey = input.sortBy.substring(1);
|
const sortingKey = input.sortBy.substring(1);
|
||||||
|
|
||||||
let data = !yoeRange
|
const data = !yoeRange
|
||||||
? await ctx.prisma.offersOffer.findMany({
|
? await ctx.prisma.offersOffer.findMany({
|
||||||
// Internship
|
// Internship
|
||||||
include: {
|
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
|
// CONVERTING
|
||||||
const currency = input.currency?.toUpperCase();
|
const currency = input.currency?.toUpperCase();
|
||||||
if (currency != null && currency in Currency) {
|
if (currency != null && currency in Currency) {
|
||||||
data = await Promise.all(
|
paginatedData = await Promise.all(
|
||||||
data.map(async (offer) => {
|
paginatedData.map(async (offer) => {
|
||||||
if (offer.offersFullTime?.totalCompensation != null) {
|
if (offer.offersFullTime?.totalCompensation != null) {
|
||||||
offer.offersFullTime.totalCompensation.value =
|
offer.offersFullTime.totalCompensation.value =
|
||||||
await convertWithDate(
|
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(
|
return getOffersResponseMapper(
|
||||||
paginatedData.map((offer) => dashboardOfferDtoMapper(offer)),
|
paginatedData.map((offer) => dashboardOfferDtoMapper(offer)),
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user