Skip to content

Commit eb05ca8

Browse files
committed
modify: 게시글 통계를 증가량 대신 그날 누적 게시글 수 통계로
1 parent 1e73b84 commit eb05ca8

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('TotalStatsRepository', () => {
124124
[userId, mockStartDate]
125125
);
126126
expect(mockPool.query).toHaveBeenCalledWith(
127-
expect.stringContaining('SUM(dp.post_count) OVER'),
127+
expect.stringContaining('SELECT COUNT(id)'),
128128
[userId, mockStartDate]
129129
);
130130
});
@@ -217,8 +217,6 @@ describe('TotalStatsRepository', () => {
217217
const calledQuery = mockPool.query.mock.calls[0][0] as string;
218218
expect(calledQuery).toContain('WITH date_series AS');
219219
expect(calledQuery).toContain('generate_series');
220-
expect(calledQuery).toContain('SUM(dp.post_count) OVER');
221-
expect(calledQuery).toContain('DATE(p.released_at)');
222220
});
223221
});
224222
});

src/repositories/totalStats.repository.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,16 @@ export class TotalStatsRepository {
7373
CURRENT_DATE,
7474
'1 day'::interval
7575
)::date AS date
76-
),
77-
daily_posts AS (
78-
SELECT
79-
DATE(p.released_at) AS date,
80-
COUNT(*) AS post_count
81-
FROM posts_post p
82-
WHERE p.user_id = $1
83-
AND p.is_active = true
84-
AND DATE(p.released_at) >= DATE($2)
85-
GROUP BY DATE(p.released_at)
8676
)
8777
SELECT
8878
ds.date,
89-
COALESCE(SUM(dp.post_count) OVER (ORDER BY ds.date), 0) AS total_value
79+
(SELECT COUNT(id)
80+
FROM posts_post p
81+
WHERE p.user_id = $1
82+
AND p.is_active = true
83+
AND DATE(p.released_at) <= ds.date
84+
) AS total_value
9085
FROM date_series ds
91-
LEFT JOIN daily_posts dp ON ds.date = dp.date
9286
ORDER BY ds.date ASC;
9387
`;
9488

0 commit comments

Comments
 (0)