add cache for website id

This commit is contained in:
formica2 2021-03-24 14:48:20 +03:00
parent f8ac987bfc
commit 2f6e7786c6
3 changed files with 38 additions and 4 deletions

View file

@ -1,4 +1,4 @@
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'lib/queries';
import { getWebsiteIDByUuidCached, getSessionByUuid, createSession } from 'lib/queries';
import { getClientInfo } from 'lib/request';
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
@ -25,13 +25,12 @@ export async function getSession(req) {
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
const website = await getWebsiteByUuid(website_uuid);
const website_id = await getWebsiteIDByUuidCached(website_uuid);
if (!website) {
if (!website_id) {
throw new Error(`Website not found: ${website_uuid}`);
}
const { website_id } = website;
const session_uuid = uuid(website_id, hostname, ip, userAgent, os);
let session = await getSessionByUuid(session_uuid);