fix event_name parameter collision. Closes #4461
This commit is contained in:
1 parent
a2374e1515
commit
1a91b5f1f3
9 files changed
+281
-21
No files matched your search
@@ -5,19 +5,26 @@ import type { QueryFilters } from '@/lib/types';
|
||||
|
||||
const FUNCTION_NAME = 'getEventDataFields';
|
||||
|
||||
export async function getEventDataFields(...args: [websiteId: string, filters: QueryFilters]) {
|
||||
export async function getEventDataFields(
|
||||
...args: [websiteId: string, eventName: string | undefined, filters: QueryFilters]
|
||||
) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
eventName: string | undefined,
|
||||
filters: QueryFilters,
|
||||
) {
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
const { filterQuery, cohortQuery, joinSessionQuery, queryParams } = parseFilters({
|
||||
...filters,
|
||||
websiteId,
|
||||
});
|
||||
const eventNameFilter = eventName ? 'and website_event.event_name = {{eventName}}' : '';
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
@@ -29,6 +36,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
join website_event on website_event.event_id = event_data.website_event_id
|
||||
and website_event.website_id = {{websiteId::uuid}}
|
||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||
${eventNameFilter}
|
||||
${cohortQuery}
|
||||
${joinSessionQuery}
|
||||
where event_data.website_id = {{websiteId::uuid}}
|
||||
@@ -37,17 +45,20 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
group by data_key, data_type
|
||||
order by "total" desc, "propertyName" asc
|
||||
`,
|
||||
queryParams,
|
||||
{ ...queryParams, eventName },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
eventName: string | undefined,
|
||||
filters: QueryFilters,
|
||||
): Promise<{ propertyName: string; dataType: number; total: number }[]> {
|
||||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const { filterQuery, cohortQuery, queryParams } = parseFilters({ ...filters, websiteId });
|
||||
const eventNameFilter = eventName ? 'and event_name = {eventName:String}' : '';
|
||||
const eventDataNameFilter = eventName ? 'and event_data.event_name = {eventName:String}' : '';
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
@@ -61,6 +72,7 @@ async function clickhouseQuery(
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${eventNameFilter}
|
||||
and event_type = 2) website_event
|
||||
on website_event.event_id = event_data.event_id
|
||||
and website_event.session_id = event_data.session_id
|
||||
@@ -68,11 +80,12 @@ async function clickhouseQuery(
|
||||
${cohortQuery}
|
||||
where event_data.website_id = {websiteId:UUID}
|
||||
and event_data.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${eventDataNameFilter}
|
||||
${filterQuery}
|
||||
group by data_key, data_type
|
||||
order by total desc, propertyName asc
|
||||
`,
|
||||
queryParams,
|
||||
{ ...queryParams, eventName },
|
||||
FUNCTION_NAME,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user