mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
use uuid
This commit is contained in:
parent
246e4e5f4f
commit
17041efaae
73 changed files with 491 additions and 874 deletions
55
queries/analytics/session/getSession.js
Normal file
55
queries/analytics/session/getSession.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||
import prisma from 'lib/prisma';
|
||||
import redis from 'lib/redis';
|
||||
|
||||
export async function getSession(...args) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(where) {
|
||||
return prisma.client.session
|
||||
.findUnique({
|
||||
where,
|
||||
})
|
||||
.then(async res => {
|
||||
if (redis.enabled && res) {
|
||||
await redis.set(`session:${res.sessionUuid}`, 1);
|
||||
}
|
||||
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
async function clickhouseQuery(sessionUuid) {
|
||||
const { rawQuery, findFirst } = clickhouse;
|
||||
const params = [sessionUuid];
|
||||
|
||||
return rawQuery(
|
||||
`select distinct
|
||||
session_id,
|
||||
website_id,
|
||||
created_at,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
device,
|
||||
screen,
|
||||
language,
|
||||
country
|
||||
from event
|
||||
where session_id = $1`,
|
||||
params,
|
||||
)
|
||||
.then(result => findFirst(result))
|
||||
.then(async res => {
|
||||
if (redis.enabled && res) {
|
||||
await redis.set(`session:${res.id}`, 1);
|
||||
}
|
||||
|
||||
return res;
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue