File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -34,10 +34,10 @@ export const postAnalyticsClickhouseCron: Cron = {
34
34
const clickhouseClient = getClickHouseClient ( ) ;
35
35
36
36
const response = await clickhouseClient . query ( {
37
- query : `
37
+ query : /* sql */ `
38
38
SELECT
39
39
post_id AS id,
40
- max( created_at) AS "updatedAt",
40
+ created_at AS "updatedAt",
41
41
sum(impressions) AS impressions,
42
42
uniqMerge(reach) AS reach,
43
43
uniqMerge(bookmarks) AS bookmarks,
@@ -48,10 +48,10 @@ export const postAnalyticsClickhouseCron: Cron = {
48
48
sum(shares_internal) AS "sharesInternal"
49
49
FROM api.post_analytics
50
50
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 ;
55
55
` ,
56
56
format : 'JSONEachRow' ,
57
57
query_params : {
You can’t perform that action at this time.
0 commit comments