diff --git a/lib/session.js b/lib/session.js index b106d54a..442de39c 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;