mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 08:37:13 +01:00
convert analytics queries
This commit is contained in:
parent
4f12933f42
commit
6ea2282f82
12 changed files with 470 additions and 52 deletions
|
|
@ -1,6 +1,24 @@
|
|||
import { parseFilters, rawQuery, getDateQuery, getDateStringQuery } from 'lib/db';
|
||||
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
import {
|
||||
rawQueryClickhouse,
|
||||
getBetweenDatesClickhouse,
|
||||
getDateQuery,
|
||||
getDateQueryClickhouse,
|
||||
getDateStringQuery,
|
||||
getDateStringQueryClickhouse,
|
||||
parseFilters,
|
||||
rawQuery,
|
||||
runAnalyticsQuery,
|
||||
} from 'lib/db';
|
||||
|
||||
export function getPageviewStats(
|
||||
export async function getPageviewStats(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
|
|
@ -32,3 +50,37 @@ export function getPageviewStats(
|
|||
params,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'UTC',
|
||||
unit = 'day',
|
||||
count = '*',
|
||||
filters = {},
|
||||
) {
|
||||
const params = [website_id];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
|
||||
return rawQueryClickhouse(
|
||||
`
|
||||
select
|
||||
${getDateStringQueryClickhouse('g.t', unit)} as t,
|
||||
g.y as y
|
||||
from
|
||||
(select
|
||||
${getDateQueryClickhouse('created_at', unit, timezone)} t,
|
||||
count(${count}) y
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id= $1
|
||||
and ${getBetweenDatesClickhouse('pageview.created_at', start_at, end_at)}
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by t) g
|
||||
order by t
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue