Skip to content

Commit

Permalink
filter out duplicate AC submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
vimkim committed Mar 8, 2024
1 parent b618d5f commit 3ac2c11
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion server/src/entities/submission.entity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Status } from '../const/boj-results';
import {
BaseEntity,
Column,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Status } from '../const/boj-results';
import Problem from './problem.entity';
import Room from './room.entity';
import User from './user.entity';
Expand Down Expand Up @@ -37,4 +37,7 @@ export default class Submission extends BaseEntity {

@ManyToOne(() => Problem, (problem) => problem.submissions, { cascade: true })
problem?: Problem;

@Column()
alreadyAccepted!: boolean;
}
5 changes: 2 additions & 3 deletions server/src/room/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ export class RoomService {
.innerJoin(
'room.submissions',
'submission',
'submission.status = :status AND submission.user_id = user.id',
'submission.status = :status AND submission.user_id = user.id AND submission.alreadyAccepted = false',
{
status: Status.ACCEPTED,
},
)
.innerJoin('submission.problem', 'problem')
.select('user.id', 'userId')
.addSelect('user.username', 'username')
.addSelect('COUNT(DISTINCT submission.problem)', 'acceptedCount')
.addSelect('COUNT(submission.id)', 'acceptedCount')
.addSelect('MAX(submission.submittedAt)', 'lastAcceptedAt')
.groupBy('user.id')
.orderBy('acceptedCount', 'DESC')
Expand Down
10 changes: 10 additions & 0 deletions server/src/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,23 @@ export class SubmissionService {
status,
);

const alreadyAccepted = await this.submissionRepository.exist({
where: {
user: { id: user.id },
problem: { id: problem.id },
room: { id: room.id },
status: Status.ACCEPTED,
},
});

return await this.submissionRepository
.create({
status,
user,
room,
problem,
submittedAt,
alreadyAccepted,
})
.save();
}
Expand Down

0 comments on commit 3ac2c11

Please sign in to comment.