fix realtime queries for stats

This commit is contained in:
Francis Cao 2024-07-23 22:44:10 -07:00
parent 174b9e4376
commit 3205b4f0f4
2 changed files with 10 additions and 4 deletions

View File

@ -47,6 +47,9 @@ async function clickhouseQuery(
eventType: EVENT_TYPE.pageView, eventType: EVENT_TYPE.pageView,
}); });
const table = unit === 'minute' ? 'website_event' : 'website_event_stats_hourly';
const columnQuery = unit === 'minute' ? 'count(*)' : 'sum(views)';
return rawQuery( return rawQuery(
` `
select select
@ -55,8 +58,8 @@ async function clickhouseQuery(
from ( from (
select select
${getDateSQL('created_at', unit, timezone)} as t, ${getDateSQL('created_at', unit, timezone)} as t,
sum(views) as y ${columnQuery} as y
from website_event_stats_hourly website_event from ${table} website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64} and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32} and event_type = {eventType:UInt32}

View File

@ -47,6 +47,9 @@ async function clickhouseQuery(
eventType: EVENT_TYPE.pageView, eventType: EVENT_TYPE.pageView,
}); });
const table = unit === 'minute' ? 'website_event' : 'website_event_stats_hourly';
const columnQuery = unit === 'minute' ? 'count(distinct session_id)' : 'uniq(session_id)';
return rawQuery( return rawQuery(
` `
select select
@ -55,8 +58,8 @@ async function clickhouseQuery(
from ( from (
select select
${getDateSQL('created_at', unit, timezone)} as t, ${getDateSQL('created_at', unit, timezone)} as t,
uniq(session_id) as y ${columnQuery} as y
from website_event_stats_hourly website_event from ${table} website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64} and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32} and event_type = {eventType:UInt32}