skip session check if using clickhouse

pull/1653/head
Brian Cao 2022-11-08 15:50:34 -08:00
parent 224e9b3718
commit c2df477374
1 changed files with 37 additions and 22 deletions

View File

@ -2,6 +2,7 @@ import { parseToken } from 'next-basics';
import { validate } from 'uuid'; import { validate } from 'uuid';
import { secret, uuid } from 'lib/crypto'; import { secret, uuid } from 'lib/crypto';
import cache from 'lib/cache'; import cache from 'lib/cache';
import clickhouse from 'lib/clickhouse';
import { getClientInfo, getJsonBody } from 'lib/request'; import { getClientInfo, getJsonBody } from 'lib/request';
import { createSession, getSession, getWebsite } from 'queries'; import { createSession, getSession, getWebsite } from 'queries';
@ -49,6 +50,7 @@ export async function findSession(req) {
// Find session // Find session
let session; let session;
if (!clickhouse.enabled) {
if (cache.enabled) { if (cache.enabled) {
session = await cache.fetchSession(sessionId); session = await cache.fetchSession(sessionId);
} else { } else {
@ -75,6 +77,19 @@ export async function findSession(req) {
} }
} }
} }
} else {
session = {
id: sessionId,
websiteId,
hostname,
browser,
os,
device,
screen,
language,
country,
};
}
return session; return session;
} }