mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 07:37:11 +01:00
Re-write CH queries to use query params.
This commit is contained in:
parent
b4bd988e4e
commit
1eb9e10d94
12 changed files with 81 additions and 100 deletions
|
|
@ -1,52 +0,0 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, PRISMA, CLICKHOUSE } from 'lib/db';
|
||||
|
||||
export async function getSessions(...args) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websites, startAt) {
|
||||
return prisma.client.session.findMany({
|
||||
where: {
|
||||
...(websites && websites.length > 0
|
||||
? {
|
||||
websiteId: {
|
||||
in: websites,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
createdAt: {
|
||||
gte: startAt,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websites, startAt) {
|
||||
const { rawQuery, getDateFormat, getCommaSeparatedStringFormat } = clickhouse;
|
||||
|
||||
return rawQuery(
|
||||
`select distinct
|
||||
session_id,
|
||||
website_id,
|
||||
created_at,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country
|
||||
from event
|
||||
where ${
|
||||
websites && websites.length > 0
|
||||
? `website_id in (${getCommaSeparatedStringFormat(websites)})`
|
||||
: '0 = 0'
|
||||
}
|
||||
and created_at >= ${getDateFormat(startAt)}`,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue