Skip to content

Commit 9d343be

Browse files
committed
refactor: 비정상 데이터 필터링 구문 개선
1 parent b39315a commit 9d343be

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/repositories/__test__/leaderboard.repo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('LeaderboardRepository', () => {
8888
await repo.getUserLeaderboard('viewCount', 30, 10);
8989

9090
expect(mockPool.query).toHaveBeenCalledWith(
91-
expect.stringContaining('HAVING SUM(COALESCE(ts.today_view, 0)) != SUM(COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0))'),
91+
expect.stringContaining('HAVING SUM(COALESCE(ss.start_view, 0)) != 0'),
9292
expect.anything(),
9393
);
9494
});
@@ -174,7 +174,7 @@ describe('LeaderboardRepository', () => {
174174
await repo.getPostLeaderboard('viewCount', 30, 10);
175175

176176
expect(mockPool.query).toHaveBeenCalledWith(
177-
expect.stringContaining('COALESCE(ts.today_view, 0) != COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0)'),
177+
expect.stringContaining('ss.post_id IS NOT NULL'),
178178
expect.anything()
179179
);
180180
});

src/repositories/leaderboard.repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class LeaderboardRepository {
3030
LEFT JOIN start_stats ss ON ss.post_id = p.id
3131
WHERE u.username IS NOT NULL
3232
GROUP BY u.id, u.email, u.username
33-
HAVING SUM(COALESCE(ts.today_view, 0)) != SUM(COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0))
33+
HAVING SUM(COALESCE(ss.start_view, 0)) != 0
3434
ORDER BY ${this.SORT_COL_MAPPING[sort]} DESC, u.id
3535
LIMIT $1;
3636
`;
@@ -68,7 +68,7 @@ export class LeaderboardRepository {
6868
AND (
6969
p.released_at >= '${pastDateKST}'
7070
OR
71-
COALESCE(ts.today_view, 0) != COALESCE(ts.today_view, 0) - COALESCE(ss.start_view, 0)
71+
ss.post_id IS NOT NULL
7272
)
7373
ORDER BY ${this.SORT_COL_MAPPING[sort]} DESC, p.id
7474
LIMIT $1;

0 commit comments

Comments
 (0)