skip session check if using clickhouse
parent
224e9b3718
commit
c2df477374
|
@ -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,31 +50,45 @@ export async function findSession(req) {
|
||||||
// Find session
|
// Find session
|
||||||
let session;
|
let session;
|
||||||
|
|
||||||
if (cache.enabled) {
|
if (!clickhouse.enabled) {
|
||||||
session = await cache.fetchSession(sessionId);
|
if (cache.enabled) {
|
||||||
} else {
|
session = await cache.fetchSession(sessionId);
|
||||||
session = await getSession({ id: sessionId });
|
} else {
|
||||||
}
|
session = await getSession({ id: sessionId });
|
||||||
|
}
|
||||||
|
|
||||||
// Create a session if not found
|
// Create a session if not found
|
||||||
if (!session) {
|
if (!session) {
|
||||||
try {
|
try {
|
||||||
session = await createSession({
|
session = await createSession({
|
||||||
id: sessionId,
|
id: sessionId,
|
||||||
websiteId,
|
websiteId,
|
||||||
hostname,
|
hostname,
|
||||||
browser,
|
browser,
|
||||||
os,
|
os,
|
||||||
device,
|
device,
|
||||||
screen,
|
screen,
|
||||||
language,
|
language,
|
||||||
country,
|
country,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!e.message.toLowerCase().includes('unique constraint')) {
|
if (!e.message.toLowerCase().includes('unique constraint')) {
|
||||||
throw e;
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
session = {
|
||||||
|
id: sessionId,
|
||||||
|
websiteId,
|
||||||
|
hostname,
|
||||||
|
browser,
|
||||||
|
os,
|
||||||
|
device,
|
||||||
|
screen,
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
|
|
Loading…
Reference in New Issue