Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

skip session check if using clickhouse

Brian Caoc2df47737493
diff --git a/lib/session.js b/lib/session.js
index b106d54ae..442de39ca 100644
--- a/lib/session.js
+++ b/lib/session.js
@@ -2,6 +2,7 @@ import { parseToken } from 'next-basics';
import { validate } from 'uuid';
import { secret, uuid } from 'lib/crypto';
import cache from 'lib/cache';
+import clickhouse from 'lib/clickhouse';
import { getClientInfo, getJsonBody } from 'lib/request';
import { createSession, getSession, getWebsite } from 'queries';
@@ -49,31 +50,45 @@ export async function findSession(req) {
// Find session
let session;
- if (cache.enabled) {
- session = await cache.fetchSession(sessionId);
- } else {
- session = await getSession({ id: sessionId });
- }
+ 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;
+ // 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,
+ websiteId,
+ hostname,
+ browser,
+ os,
+ device,
+ screen,
+ language,
+ country,
+ };
}
return session;