mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 15:47:13 +01:00
Feat/um 305 unique session ch (#2065)
* Add session_data / session redis to CH. * Add mysql migration.
This commit is contained in:
parent
1038a54fe4
commit
b484286523
23 changed files with 405 additions and 300 deletions
|
|
@ -1,43 +1,8 @@
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getSession(args: { id: string }) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(where: Prisma.SessionWhereUniqueInput) {
|
||||
export async function getSession(where: Prisma.SessionWhereUniqueInput) {
|
||||
return prisma.client.session.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery({ id: sessionId }: { id: string }) {
|
||||
const { rawQuery, findFirst } = clickhouse;
|
||||
const params = { sessionId };
|
||||
|
||||
return rawQuery(
|
||||
`select
|
||||
session_id,
|
||||
website_id,
|
||||
created_at,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
subdivision1,
|
||||
subdivision2,
|
||||
city
|
||||
from website_event
|
||||
where session_id = {sessionId:UUID}
|
||||
limit 1`,
|
||||
params,
|
||||
).then(result => findFirst(result));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue