mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 12:35:38 +01:00
Feat/um 154 add event data rewrite queries (#1739)
* Cherry pick prisma query protection. * Re-write CH queries to use query params. * Fix query. * Fix modal. Re-add form css.
This commit is contained in:
parent
4c202741c2
commit
0409a7d261
19 changed files with 257 additions and 185 deletions
|
|
@ -33,17 +33,22 @@ async function relationalQuery(
|
|||
},
|
||||
) {
|
||||
const { startDate, endDate, column, filters = {} } = data;
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
const params = [startDate, endDate];
|
||||
const { rawQuery, parseFilters, toUuid } = prisma;
|
||||
const params: any = {
|
||||
websiteId,
|
||||
startDate,
|
||||
endDate,
|
||||
type: EVENT_TYPE.pageView,
|
||||
};
|
||||
const { filterQuery, joinSession } = parseFilters(filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`select ${column} x, count(*) y
|
||||
from website_event
|
||||
${joinSession}
|
||||
where website_id='${websiteId}'
|
||||
and website_event.created_at between $1 and $2
|
||||
and event_type = ${EVENT_TYPE.pageView}
|
||||
where website_event.website_id = $1${toUuid()}
|
||||
and website_event.created_at between $2 and $3
|
||||
and event_type = $4
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 2 desc`,
|
||||
|
|
@ -63,15 +68,19 @@ async function clickhouseQuery(
|
|||
const { startDate, endDate, column, filters = {} } = data;
|
||||
const { rawQuery, parseFilters, getBetweenDates } = clickhouse;
|
||||
const website = await cache.fetchWebsite(websiteId);
|
||||
const params = [websiteId, website?.revId || 0, EVENT_TYPE.pageView];
|
||||
const params = {
|
||||
websiteId,
|
||||
revId: website?.revId || 0,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
};
|
||||
const { filterQuery } = parseFilters(filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`select ${column} x, count(*) y
|
||||
from event
|
||||
where website_id = $1
|
||||
and rev_id = $2
|
||||
and event_type = $3
|
||||
where website_id = {websiteId:UUID}
|
||||
and rev_id = {revId:UInt32}
|
||||
and event_type = {eventType:UInt32}
|
||||
and ${getBetweenDates('created_at', startDate, endDate)}
|
||||
${filterQuery}
|
||||
group by x
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue