Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ALTER TABLE api.post_analytics_events_mv
MODIFY QUERY
SELECT target_id AS post_id,
sumIf(toUInt64(1), event_name = 'share post') AS shares_external,
sumIf(toUInt64(1), event_name = 'share to squad') AS shares_internal,
uniqStateIf(user_id, event_name = 'bookmark post') AS bookmarks,
sumIf(toUInt64(1), (event_name = 'impression') AND (target_type = 'post')) AS impressions,
uniqStateIf(user_id, (event_name = 'impression') AND (target_type = 'post')) AS reach,
uniqStateIf(user_id, (event_name = 'impression') AND (target_type = 'post')) AS reach_all,
sumIf(toUInt64(1), (event_name = 'click') AND (target_type = 'post')) AS clicks,
sumIf(toUInt64(1), (event_name = 'go to link') AND (target_type = 'post')) AS go_to_link,
max(server_timestamp) AS created_at
FROM events.raw_events
WHERE (event_name IN ('share post', 'bookmark post', 'impression', 'share to squad', 'click', 'go to link'))
AND (target_id IS NOT NULL)
AND (server_timestamp > '2025-10-08 13:00:00')
GROUP BY target_id
SETTINGS materialized_views_ignore_errors = 1;
2 changes: 1 addition & 1 deletion src/cron/postAnalyticsClickhouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const postAnalyticsClickhouseCron: Cron = {
sum(clicks_ads) AS "clicksAds",
sum(go_to_link) AS "goToLink"
FROM api.post_analytics
WHERE "created_at" > {lastRunAt: DateTime}
FINAL
GROUP BY id
HAVING "updatedAt" > {lastRunAt: DateTime}
ORDER BY "updatedAt" DESC;
Expand Down
Loading