update schema and queries to implement reset_at

This commit is contained in:
Francis Cao 2023-03-27 11:25:16 -07:00
parent 43ef6884df
commit 14e4a090bb
15 changed files with 74 additions and 59 deletions

View file

@ -48,7 +48,9 @@ async function relationalQuery(
) {
const { startDate, endDate, timeSeries, eventName, urlPath, filters } = data;
const { toUuid, rawQuery, getEventDataFilterQuery, getDateQuery } = prisma;
const params: any = [websiteId, startDate, endDate, eventName || ''];
const website = await cache.fetchWebsite(websiteId);
const resetDate = website?.resetAt || website?.createdAt;
const params: any = [websiteId, resetDate, startDate, endDate, eventName || ''];
return rawQuery(
`select
@ -65,8 +67,9 @@ async function relationalQuery(
: ''
}
where website_id = $1${toUuid()}
and created_at between $2 and $3
${eventName ? `and eventName = $4` : ''}
and created_at >= $2
and created_at between $3 and $4
${eventName ? `and eventName = $5` : ''}
${getEventDataFilterQuery(filters, params)}
${timeSeries ? 'group by t' : ''}`,
params,
@ -93,9 +96,11 @@ async function clickhouseQuery(
},
) {
const { startDate, endDate, timeSeries, eventName, urlPath, filters } = data;
const { rawQuery, getBetweenDates, getDateQuery, getEventDataFilterQuery } = clickhouse;
const { rawQuery, getDateFormat, getBetweenDates, getDateQuery, getEventDataFilterQuery } =
clickhouse;
const website = await cache.fetchWebsite(websiteId);
const params = { websiteId, revId: website?.revId || 0 };
const resetDate = website?.resetAt || website?.createdAt;
const params = { websiteId };
return rawQuery(
`select
@ -107,8 +112,8 @@ async function clickhouseQuery(
}
from event_data
where website_id = {websiteId:UUID}
and rev_id = {revId:UInt32}
${eventName ? `and eventName = ${eventName}` : ''}
and created_at >= ${getDateFormat(resetDate)}
and ${getBetweenDates('created_at', startDate, endDate)}
${getEventDataFilterQuery(filters, params)}
${timeSeries ? 'group by t' : ''}`,

View file

@ -11,7 +11,6 @@ export async function saveEventData(args: {
websiteId: string;
eventId: string;
sessionId?: string;
revId?: number;
urlPath?: string;
eventName?: string;
eventData: EventData;
@ -58,13 +57,12 @@ async function clickhouseQuery(data: {
websiteId: string;
eventId: string;
sessionId?: string;
revId?: number;
urlPath?: string;
eventName?: string;
eventData: EventData;
createdAt?: string;
}) {
const { websiteId, sessionId, eventId, revId, urlPath, eventName, eventData, createdAt } = data;
const { websiteId, sessionId, eventId, urlPath, eventName, eventData, createdAt } = data;
const { getDateFormat, sendMessages } = kafka;
@ -74,7 +72,6 @@ async function clickhouseQuery(data: {
website_id: websiteId,
session_id: sessionId,
event_id: eventId,
rev_id: revId,
url_path: urlPath,
event_name: eventName,
event_key: a.key,