Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/api/repository/winnings.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,27 @@ export class WinningsRepository {
!winnerIds && !!externalIds?.length,
);

const [winnings, count] = await this.prisma.$transaction([
this.prisma.winnings.findMany({
where: queryWhere,
include: {
payment: {
where: {
installment_number: 1,
},
orderBy: [
{
created_at: 'desc',
},
],
const winnings = await this.prisma.winnings.findMany({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The change from a single transaction to separate queries for findMany and count could lead to potential issues with data consistency if the data changes between the two queries. Consider if this change is necessary and if so, document the reasoning or explore alternative solutions to maintain atomicity.

where: queryWhere,
include: {
payment: {
where: {
installment_number: 1,
},
origin: true,
orderBy: [
{
created_at: 'desc',
},
],
},
orderBy,
skip: searchProps.offset,
take: searchProps.limit,
}),
this.prisma.winnings.count({ where: queryWhere }),
]);
origin: true,
},
orderBy,
skip: searchProps.offset,
take: searchProps.limit,
});

const count = await this.prisma.winnings.count({ where: queryWhere });

const usersPayoutStatusMap = winnings?.length
? await this.getUsersPayoutStatusForWinnings(winnings)
Expand Down
7 changes: 5 additions & 2 deletions src/shared/global/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export class PrismaService

constructor() {
super({
transactionOptions: {
timeout: 20000, // 20s
},
log: [
{ level: 'query', emit: 'event' },
{ level: 'info', emit: 'event' },
Expand All @@ -26,8 +29,8 @@ export class PrismaService
this.$on('query' as never, (e: Prisma.QueryEvent) => {
const queryTime = e.duration;

// log slow queries (> 500ms)
if (queryTime > 500) {
// log slow queries (> 5s)
if (queryTime > 5000) {
this.logger.warn(
`Slow query detected! Duration: ${queryTime}ms | Query: ${e.query}`,
);
Expand Down