Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Mike Cao 2024-03-29 11:48:23 -07:00
commit 5a2330ba2a

View File

@ -26,15 +26,7 @@ async function relationalQuery(
endDate: Date; endDate: Date;
timezone?: string; timezone?: string;
}, },
): Promise< ) {
{
date: string;
day: number;
visitors: number;
returnVisitors: number;
percentage: number;
}[]
> {
const { startDate, endDate } = filters; const { startDate, endDate } = filters;
const { rawQuery } = prisma; const { rawQuery } = prisma;
@ -44,7 +36,7 @@ async function relationalQuery(
from website_event from website_event
where website_id = {{websiteId::uuid}} where website_id = {{websiteId::uuid}}
and created_at between {{startDate}} and {{endDate}} and created_at between {{startDate}} and {{endDate}}
and url_query is not null and coalesce(url_query, '') != ''
and event_type = 1 and event_type = 1
group by 1 group by 1
`, `,
@ -53,9 +45,7 @@ async function relationalQuery(
startDate, startDate,
endDate, endDate,
}, },
).then(results => { ).then(result => parseParameters(result as any[]));
return results;
});
} }
async function clickhouseQuery( async function clickhouseQuery(
@ -65,15 +55,7 @@ async function clickhouseQuery(
endDate: Date; endDate: Date;
timezone?: string; timezone?: string;
}, },
): Promise< ) {
{
date: string;
day: number;
visitors: number;
returnVisitors: number;
percentage: number;
}[]
> {
const { startDate, endDate } = filters; const { startDate, endDate } = filters;
const { rawQuery } = clickhouse; const { rawQuery } = clickhouse;
@ -104,11 +86,11 @@ function parseParameters(data: any[]) {
if (key.match(/^utm_(\w+)$/)) { if (key.match(/^utm_(\w+)$/)) {
const name = safeDecodeURIComponent(value); const name = safeDecodeURIComponent(value);
if (!obj[key]) { if (!obj[key]) {
obj[key] = { [name]: +num }; obj[key] = { [name]: Number(num) };
} else if (!obj[key][name]) { } else if (!obj[key][name]) {
obj[key][name] = +num; obj[key][name] = Number(num);
} else { } else {
obj[key][name] += +num; obj[key][name] += Number(num);
} }
} }
} }