mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 17:15:37 +01:00
Database refactoring.
This commit is contained in:
parent
bb184dc2cc
commit
467c7f289f
37 changed files with 566 additions and 591 deletions
|
|
@ -1,12 +1,11 @@
|
|||
import { subMinutes } from 'date-fns';
|
||||
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
import { rawQuery } from 'lib/relational';
|
||||
import { runAnalyticsQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
|
||||
export async function getActiveVisitors(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[RELATIONAL]: () => relationalQuery(...args),
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
|
@ -15,27 +14,24 @@ async function relationalQuery(website_id) {
|
|||
const date = subMinutes(new Date(), 5);
|
||||
const params = [website_id, date];
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select count(distinct session_id) x
|
||||
return prisma.rawQuery(
|
||||
`select count(distinct session_id) x
|
||||
from pageview
|
||||
where website_id = $1
|
||||
and created_at >= $2
|
||||
`,
|
||||
and created_at >= $2`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(website_id) {
|
||||
const { rawQuery, getDateFormat } = clickhouse;
|
||||
const params = [website_id];
|
||||
|
||||
return clickhouse.rawQuery(
|
||||
`
|
||||
select count(distinct session_uuid) x
|
||||
return rawQuery(
|
||||
`select count(distinct session_uuid) x
|
||||
from pageview
|
||||
where website_id = $1
|
||||
and created_at >= ${clickhouse.getDateFormat(subMinutes(new Date(), 5))}
|
||||
`,
|
||||
and created_at >= ${getDateFormat(subMinutes(new Date(), 5))}`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue