mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 16:17:13 +01:00
Refactored redis usage. Added lib/cache.
This commit is contained in:
parent
3485b6268b
commit
f118bc95c1
22 changed files with 236 additions and 221 deletions
|
|
@ -1,18 +1,11 @@
|
|||
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),
|
||||
}).then(async data => {
|
||||
if (redis.enabled && data) {
|
||||
await redis.set(`session:${data.id}`, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +20,7 @@ async function clickhouseQuery(sessionId) {
|
|||
const params = [sessionId];
|
||||
|
||||
return rawQuery(
|
||||
`select distinct
|
||||
`select
|
||||
session_id,
|
||||
website_id,
|
||||
created_at,
|
||||
|
|
@ -39,7 +32,8 @@ async function clickhouseQuery(sessionId) {
|
|||
language,
|
||||
country
|
||||
from event
|
||||
where session_id = $1`,
|
||||
where session_id = $1
|
||||
limit 1`,
|
||||
params,
|
||||
).then(result => findFirst(result));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue