mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Updated Clickhouse session logic.
This commit is contained in:
parent
e9c8d16d5b
commit
1a8c7c42f4
@ -47,38 +47,9 @@ export async function findSession(req) {
|
|||||||
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
|
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
|
||||||
const sessionId = uuid(websiteId, hostname, ip, userAgent);
|
const sessionId = uuid(websiteId, hostname, ip, userAgent);
|
||||||
|
|
||||||
// Find session
|
// Clickhouse does not require session lookup
|
||||||
let session;
|
if (clickhouse.enabled) {
|
||||||
|
return {
|
||||||
if (!clickhouse.enabled) {
|
|
||||||
if (cache.enabled) {
|
|
||||||
session = await cache.fetchSession(sessionId);
|
|
||||||
} else {
|
|
||||||
session = await getSession({ id: sessionId });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a session if not found
|
|
||||||
if (!session) {
|
|
||||||
try {
|
|
||||||
session = await createSession({
|
|
||||||
id: sessionId,
|
|
||||||
websiteId,
|
|
||||||
hostname,
|
|
||||||
browser,
|
|
||||||
os,
|
|
||||||
device,
|
|
||||||
screen,
|
|
||||||
language,
|
|
||||||
country,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
if (!e.message.toLowerCase().includes('unique constraint')) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
session = {
|
|
||||||
id: sessionId,
|
id: sessionId,
|
||||||
websiteId,
|
websiteId,
|
||||||
hostname,
|
hostname,
|
||||||
@ -91,5 +62,35 @@ export async function findSession(req) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find session
|
||||||
|
let session;
|
||||||
|
|
||||||
|
if (cache.enabled) {
|
||||||
|
session = await cache.fetchSession(sessionId);
|
||||||
|
} else {
|
||||||
|
session = await getSession({ id: sessionId });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a session if not found
|
||||||
|
if (!session) {
|
||||||
|
try {
|
||||||
|
session = await createSession({
|
||||||
|
id: sessionId,
|
||||||
|
websiteId,
|
||||||
|
hostname,
|
||||||
|
browser,
|
||||||
|
os,
|
||||||
|
device,
|
||||||
|
screen,
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!e.message.toLowerCase().includes('unique constraint')) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user