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