Skip to content
Prev Previous commit
refactor: 비정상 데이터 필터링 구문 개선
  • Loading branch information
ooheunda committed Aug 27, 2025
commit 9d343be0cc8a14e73065c8827be399ea720d55e3
4 changes: 2 additions & 2 deletions src/repositories/__test__/leaderboard.repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('LeaderboardRepository', () => {
await repo.getUserLeaderboard('viewCount', 30, 10);

expect(mockPool.query).toHaveBeenCalledWith(
expect.stringContaining('HAVING SUM(COALESCE(ts.today_view, 0)) != SUM(COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0))'),
expect.stringContaining('HAVING SUM(COALESCE(ss.start_view, 0)) != 0'),
expect.anything(),
);
});
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('LeaderboardRepository', () => {
await repo.getPostLeaderboard('viewCount', 30, 10);

expect(mockPool.query).toHaveBeenCalledWith(
expect.stringContaining('COALESCE(ts.today_view, 0) != COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0)'),
expect.stringContaining('ss.post_id IS NOT NULL'),
expect.anything()
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/leaderboard.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class LeaderboardRepository {
LEFT JOIN start_stats ss ON ss.post_id = p.id
WHERE u.username IS NOT NULL
GROUP BY u.id, u.email, u.username
HAVING SUM(COALESCE(ts.today_view, 0)) != SUM(COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0))
HAVING SUM(COALESCE(ss.start_view, 0)) != 0
ORDER BY ${this.SORT_COL_MAPPING[sort]} DESC, u.id
LIMIT $1;
`;
Expand Down Expand Up @@ -68,7 +68,7 @@ export class LeaderboardRepository {
AND (
p.released_at >= '${pastDateKST}'
OR
COALESCE(ts.today_view, 0) != COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0)
ss.post_id IS NOT NULL
)
ORDER BY ${this.SORT_COL_MAPPING[sort]} DESC, p.id
LIMIT $1;
Expand Down