mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 02:06:19 +01:00
remove postgres collect
This commit is contained in:
parent
ae46520930
commit
86bd9a7793
@ -1,14 +1,13 @@
|
||||
import { parseToken } from 'next-basics';
|
||||
import { validate } from 'uuid';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import redis, { DELETED } from 'lib/redis';
|
||||
import { getClientInfo, getJsonBody } from 'lib/request';
|
||||
import { createSession, getSessionByUuid, getWebsiteByUuid } from 'queries';
|
||||
import { parseToken } from 'next-basics';
|
||||
import { getWebsiteByUuid } from 'queries';
|
||||
import { validate } from 'uuid';
|
||||
|
||||
export async function getSession(req) {
|
||||
const { payload } = getJsonBody(req);
|
||||
const hasRedis = process.env.REDIS_URL;
|
||||
const hasClickhouse = process.env.CLICKHOUSE_URL;
|
||||
|
||||
if (!payload) {
|
||||
throw new Error('Invalid request');
|
||||
@ -53,49 +52,17 @@ export async function getSession(req) {
|
||||
let sessionId = null;
|
||||
let session = null;
|
||||
|
||||
if (!hasClickhouse) {
|
||||
// Check if session exists
|
||||
if (hasRedis) {
|
||||
sessionId = Number(await redis.client.get(`session:${session_uuid}`));
|
||||
}
|
||||
|
||||
// Check database if does not exists in Redis
|
||||
if (!sessionId) {
|
||||
session = await getSessionByUuid(session_uuid);
|
||||
sessionId = session ? session.session_id : null;
|
||||
}
|
||||
|
||||
if (!sessionId) {
|
||||
try {
|
||||
session = await createSession(websiteId, {
|
||||
session_uuid,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
device,
|
||||
});
|
||||
} catch (e) {
|
||||
if (!e.message.toLowerCase().includes('unique constraint')) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
session = {
|
||||
session_id: sessionId,
|
||||
session_uuid,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
device,
|
||||
};
|
||||
}
|
||||
session = {
|
||||
session_id: sessionId,
|
||||
session_uuid,
|
||||
hostname,
|
||||
browser,
|
||||
os,
|
||||
screen,
|
||||
language,
|
||||
country,
|
||||
device,
|
||||
};
|
||||
|
||||
return {
|
||||
website_id: websiteId,
|
||||
|
Loading…
Reference in New Issue
Block a user