mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
cleanup cohort/filtering for some queries
This commit is contained in:
parent
6829d96862
commit
69aa4ca035
7 changed files with 17 additions and 20 deletions
|
|
@ -36,7 +36,7 @@ export function EventProperties({ websiteId }: { websiteId: string }) {
|
|||
gap="6"
|
||||
>
|
||||
{data && (
|
||||
<Grid columns="repeat(auto-fill, minmax(300px, 1fr))" gap>
|
||||
<Grid columns="repeat(auto-fill, minmax(300px, 1fr))" marginBottom="3" gap>
|
||||
<Select
|
||||
label={formatMessage(labels.event)}
|
||||
value={eventName}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ export async function GET(
|
|||
}
|
||||
|
||||
if (type === 'channel') {
|
||||
const data = await getChannelExpandedMetrics(websiteId, { limit, offset }, filters);
|
||||
const data = await getChannelExpandedMetrics(websiteId, filters);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ async function relationalQuery(
|
|||
limit ${limit}
|
||||
offset ${offset}
|
||||
`,
|
||||
queryParams,
|
||||
{ ...queryParams, ...parameters },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -80,15 +80,15 @@ async function clickhouseQuery(
|
|||
`select ${column} x,
|
||||
count(*) as y
|
||||
from website_event
|
||||
${cohortQuery}
|
||||
${cohortQuery}
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${filterQuery}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${filterQuery}
|
||||
group by x
|
||||
order by y desc
|
||||
limit ${limit}
|
||||
offset ${offset}
|
||||
`,
|
||||
queryParams,
|
||||
{ ...queryParams, ...parameters },
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export interface ChannelExpandedMetricsData {
|
|||
}
|
||||
|
||||
export async function getChannelExpandedMetrics(
|
||||
...args: [websiteId: string, parameters: ChannelExpandedMetricsParameters, filters?: QueryFilters]
|
||||
...args: [websiteId: string, filters?: QueryFilters]
|
||||
): Promise<ChannelExpandedMetricsData[]> {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
|
|
@ -37,7 +37,6 @@ export async function getChannelExpandedMetrics(
|
|||
|
||||
async function relationalQuery(
|
||||
websiteId: string,
|
||||
parameters: ChannelExpandedMetricsParameters,
|
||||
filters: QueryFilters,
|
||||
): Promise<ChannelExpandedMetricsData[]> {
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
|
|
@ -79,16 +78,14 @@ async function relationalQuery(
|
|||
group by x
|
||||
order by y desc;
|
||||
`,
|
||||
{ ...queryParams, ...parameters },
|
||||
queryParams,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(
|
||||
websiteId: string,
|
||||
parameters: ChannelExpandedMetricsParameters,
|
||||
filters: QueryFilters,
|
||||
): Promise<ChannelExpandedMetricsData[]> {
|
||||
const { limit = 500, offset = 0 } = parameters;
|
||||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const { queryParams, filterQuery, cohortQuery } = parseFilters({
|
||||
...filters,
|
||||
|
|
@ -145,11 +142,9 @@ async function clickhouseQuery(
|
|||
group by prefix, name, session_id, visit_id
|
||||
) as t
|
||||
group by name
|
||||
order by visitors desc, visits desc
|
||||
limit ${limit}
|
||||
offset ${offset}
|
||||
order by visitors desc, visits desc;
|
||||
`,
|
||||
{ ...queryParams, ...parameters },
|
||||
queryParams,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ async function relationalQuery(
|
|||
limit ${limit}
|
||||
offset ${offset}
|
||||
`,
|
||||
queryParams,
|
||||
{ ...queryParams, ...parameters },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -184,5 +184,5 @@ async function clickhouseQuery(
|
|||
`;
|
||||
}
|
||||
|
||||
return rawQuery(sql, queryParams);
|
||||
return rawQuery(sql, { ...queryParams, ...parameters });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import clickhouse from '@/lib/clickhouse';
|
||||
import { EVENT_TYPE } from '@/lib/constants';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
|
@ -31,6 +32,7 @@ async function relationalQuery(
|
|||
websiteId,
|
||||
startDate,
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
});
|
||||
|
||||
return rawQuery(
|
||||
|
|
@ -41,7 +43,6 @@ async function relationalQuery(
|
|||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and coalesce(${column}, '') != ''
|
||||
and event_type = 1
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 2 desc
|
||||
|
|
@ -62,6 +63,7 @@ async function clickhouseQuery(
|
|||
websiteId,
|
||||
startDate,
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
});
|
||||
|
||||
return rawQuery(
|
||||
|
|
@ -72,7 +74,6 @@ async function clickhouseQuery(
|
|||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and ${column} != ''
|
||||
and event_type = 1
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 2 desc
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ async function clickhouseQuery(
|
|||
${getDateSQL('website_event.created_at', unit, timezone)} as t,
|
||||
uniq(session_id) as y
|
||||
from website_event_stats_hourly as website_event
|
||||
${cohortQuery}
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
${filterQuery}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue