Skip to content

Commit

Permalink
sw page optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed May 10, 2024
1 parent 29fec9e commit c3d2016
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
37 changes: 37 additions & 0 deletions src/features/ticket/ticket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ export class TicketService {
},
},
},
order: {
createdAt: 'DESC',
},
take: 50,
});
}

Expand Down Expand Up @@ -317,8 +321,41 @@ export class TicketService {
},
},
},
take: 50,
order: {
createdAt: 'DESC',
},
});
}

async getNeedsTickets(needIds: number[]): Promise<TicketEntity[]> {
const queryBuilder = this.ticketRepository
.createQueryBuilder('ticket')
.leftJoinAndMapOne(
'ticket.need',
NeedEntity,
'need',
' need.flaskId = ticket.flaskNeedId',
)
.where('need.flaskId IN (:...needIds)', { needIds: needIds })
.select([
'ticket',
'need.id',
'need.nameTranslations',
'need.title',
'need.imageUrl',
'need.category',
'need.type',
'need.status',
'need.cost',
'need.isDeleted',
'need.created',
'need.confirmDate',
])
.cache(6000);
return await queryBuilder.getMany();
}

getUserOnlyArrivalTickets(flaskUserId: number): Promise<TicketEntity[]> {
return this.ticketRepository.find({
relations: {
Expand Down
15 changes: 8 additions & 7 deletions src/features/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,20 @@ export class UserController {
const time3 = new Date().getTime();
// add IPFS + tickets for every need
try {
let tickets: TicketEntity[];
let signatures: SignatureEntity[];
let ipfs: IpfsEntity;
if (role === SAYPlatformRoles.AUDITOR) {
tickets = await this.ticketService.getTickets();
} else {
tickets = await this.ticketService.getUserTickets(panelFlaskUserId);
}

const list: number[] = [];
allNeeds.forEach((column) => {
for (let i = 0; i < column.length; i++) {
list.push(column[i].id);
}
});
const tickets = await this.ticketService.getNeedsTickets(list);
console.log(
'\x1b[33m%s\x1b[0m',
`Taking care of Need signatures + Tickets...\n`,
);

for (let i = 0; i < allNeeds.length; i++) {
for (let k = 0; k < allNeeds[i].length; k++) {
const fetchedNeed = allNeeds[i][k];
Expand Down

0 comments on commit c3d2016

Please sign in to comment.