mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 08:37:13 +01:00
Refactored query filters.
This commit is contained in:
parent
b65c478689
commit
157862834d
16 changed files with 118 additions and 147 deletions
|
|
@ -47,11 +47,12 @@ async function relationalQuery(websiteId: string, criteria: GetEventMetricsCrite
|
|||
order by 2
|
||||
`,
|
||||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.customEvent,
|
||||
...filters,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -82,6 +83,7 @@ async function clickhouseQuery(websiteId: string, criteria: GetEventMetricsCrite
|
|||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.customEvent,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,22 +34,6 @@ async function relationalQuery(
|
|||
const { startDate, endDate, filters = {}, column } = criteria;
|
||||
const { rawQuery, parseFilters } = prisma;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const params: any = {
|
||||
websiteId,
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
...filters,
|
||||
};
|
||||
|
||||
let excludeDomain = '';
|
||||
|
||||
if (column === 'referrer_domain') {
|
||||
excludeDomain =
|
||||
'and (website_event.referrer_domain != {{domain}} or website_event.referrer_domain is null)';
|
||||
|
||||
params.domain = website.domain;
|
||||
}
|
||||
|
||||
const { filterQuery, joinSession } = parseFilters(filters);
|
||||
|
||||
|
|
@ -61,13 +45,19 @@ async function relationalQuery(
|
|||
where website_event.website_id = {{websiteId::uuid}}
|
||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||
and event_type = {{eventType}}
|
||||
${excludeDomain}
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 2 desc
|
||||
limit 100
|
||||
`,
|
||||
params,
|
||||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -83,21 +73,6 @@ async function clickhouseQuery(
|
|||
const { startDate, endDate, filters = {}, column } = criteria;
|
||||
const { rawQuery, parseFilters } = clickhouse;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const params = {
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
domain: undefined,
|
||||
};
|
||||
|
||||
let excludeDomain = '';
|
||||
|
||||
if (column === 'referrer_domain') {
|
||||
excludeDomain = 'and referrer_domain != {domain:String}';
|
||||
params.domain = website.domain;
|
||||
}
|
||||
|
||||
const { filterQuery } = parseFilters(filters);
|
||||
|
||||
|
|
@ -108,12 +83,18 @@ async function clickhouseQuery(
|
|||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime} and {endDate:DateTime}
|
||||
and event_type = {eventType:UInt32}
|
||||
${excludeDomain}
|
||||
${filterQuery}
|
||||
group by x
|
||||
order by y desc
|
||||
limit 100
|
||||
`,
|
||||
params,
|
||||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ async function relationalQuery(websiteId: string, criteria: PageviewStatsCriteri
|
|||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -93,6 +94,7 @@ async function clickhouseQuery(websiteId: string, criteria: PageviewStatsCriteri
|
|||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ async function relationalQuery(
|
|||
y: number;
|
||||
}[]
|
||||
> {
|
||||
const { startDate, endDate, fields = [], filters = [], groups = [] } = criteria;
|
||||
const { startDate, endDate, filters = [] } = criteria;
|
||||
const { parseFilters, rawQuery } = prisma;
|
||||
const website = await loadWebsite(websiteId);
|
||||
const params = {};
|
||||
|
|
@ -107,7 +107,7 @@ function parseFields(fields) {
|
|||
|
||||
if (!count && value === 'total') {
|
||||
count = true;
|
||||
arr = arr.concat(`count(*) as total`);
|
||||
arr = arr.concat(`count(*) as views`);
|
||||
} else if (!distinct && value === 'unique') {
|
||||
distinct = true;
|
||||
//arr = arr.concat(`count(distinct ${name})`);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
import { DEFAULT_RESET_DATE, EVENT_TYPE } from 'lib/constants';
|
||||
import { EVENT_TYPE } from 'lib/constants';
|
||||
import { loadWebsite } from 'lib/load';
|
||||
import { maxDate } from 'lib/date';
|
||||
|
||||
|
|
@ -28,14 +28,9 @@ async function relationalQuery(
|
|||
|
||||
return rawQuery(
|
||||
`select ${column} x, count(*) y
|
||||
from session as s
|
||||
where s.session_id in (
|
||||
select website_event.session_id
|
||||
from website_event
|
||||
join website
|
||||
on website_event.website_id = website.website_id
|
||||
${joinSession}
|
||||
where website.website_id = {{websiteId::uuid}}
|
||||
${joinSession}
|
||||
where website_event.website_id = {{websiteId::uuid}}
|
||||
and website_event.created_at between {{startDate}} and {{endDate}}
|
||||
${filterQuery}
|
||||
) as t
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ async function relationalQuery(websiteId: string, criteria: SessionStatsCriteria
|
|||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -93,6 +94,7 @@ async function clickhouseQuery(websiteId: string, criteria: SessionStatsCriteria
|
|||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,11 +51,12 @@ async function relationalQuery(
|
|||
) as t
|
||||
`,
|
||||
{
|
||||
...filters,
|
||||
websiteId,
|
||||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
...filters,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -97,6 +98,7 @@ async function clickhouseQuery(
|
|||
startDate: maxDate(startDate, website.resetAt),
|
||||
endDate,
|
||||
eventType: EVENT_TYPE.pageView,
|
||||
domain: website.domain,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue