mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 16:45:35 +01:00
Refactored queries.
This commit is contained in:
parent
e4bd314bd6
commit
4bd3ef8e12
19 changed files with 330 additions and 408 deletions
|
|
@ -34,18 +34,16 @@ async function relationalQuery(
|
|||
}[]
|
||||
> {
|
||||
const { windowMinutes, startDate, endDate, urls } = criteria;
|
||||
const { rawQuery, getFunnelQuery, toUuid } = prisma;
|
||||
const { rawQuery, getFunnelQuery } = prisma;
|
||||
const { levelQuery, sumQuery, urlFilterQuery } = getFunnelQuery(urls, windowMinutes);
|
||||
|
||||
const params: any = [websiteId, startDate, endDate, ...urls];
|
||||
|
||||
return rawQuery(
|
||||
`WITH level0 AS (
|
||||
select distinct session_id, url_path, referrer_path, created_at
|
||||
from website_event
|
||||
where url_path in (${urlFilterQuery})
|
||||
and website_id = $1${toUuid()}
|
||||
and created_at between $2 and $3
|
||||
and website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
),level1 AS (
|
||||
select distinct session_id, url_path as level_1_url, created_at as level_1_created_at
|
||||
from level0
|
||||
|
|
@ -55,7 +53,7 @@ async function relationalQuery(
|
|||
SELECT ${sumQuery}
|
||||
from level${urls.length};
|
||||
`,
|
||||
params,
|
||||
{ websiteId, startDate, endDate, ...urls },
|
||||
).then((a: { [key: string]: number }) => {
|
||||
return urls.map((b, i) => ({ x: b, y: a[0][`level${i + 1}`] || 0 }));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue