Skip to content

Commit d4c410a

Browse files
authored
feat: adjust clickhouse query after schema changes (#2980)
1 parent 7038e2f commit d4c410a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/cron/postAnalyticsClickhouse.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export const postAnalyticsClickhouseCron: Cron = {
3434
const clickhouseClient = getClickHouseClient();
3535

3636
const response = await clickhouseClient.query({
37-
query: `
37+
query: /* sql */ `
3838
SELECT
3939
post_id AS id,
40-
max(created_at) AS "updatedAt",
40+
created_at AS "updatedAt",
4141
sum(impressions) AS impressions,
4242
uniqMerge(reach) AS reach,
4343
uniqMerge(bookmarks) AS bookmarks,
@@ -48,10 +48,10 @@ export const postAnalyticsClickhouseCron: Cron = {
4848
sum(shares_internal) AS "sharesInternal"
4949
FROM api.post_analytics
5050
FINAL
51-
WHERE created_at >= now() - INTERVAL 45 DAY
52-
GROUP BY post_id
53-
HAVING "updatedAt" > {lastRunAt: DateTime}
54-
ORDER BY "updatedAt" DESC;
51+
WHERE created_at > {lastRunAt: DateTime}
52+
GROUP BY post_id, created_at
53+
ORDER BY created_at DESC
54+
LIMIT 1 BY post_id;
5555
`,
5656
format: 'JSONEachRow',
5757
query_params: {

0 commit comments

Comments
 (0)