mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 15:47:13 +01:00
Added try catch to redis methods.
This commit is contained in:
parent
aaa51e72d3
commit
0e4f4affea
1 changed files with 28 additions and 17 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { serializeError } from 'serialize-error';
|
||||||
import { getWebsiteSession, getWebsite } from 'queries';
|
import { getWebsiteSession, getWebsite } from 'queries';
|
||||||
import { Website, Session } from '@prisma/client';
|
import { Website, Session } from '@prisma/client';
|
||||||
import { getClient, redisEnabled } from '@umami/redis-client';
|
import { getClient, redisEnabled } from '@umami/redis-client';
|
||||||
|
|
@ -5,16 +6,21 @@ import { getClient, redisEnabled } from '@umami/redis-client';
|
||||||
export async function fetchWebsite(websiteId: string): Promise<Website> {
|
export async function fetchWebsite(websiteId: string): Promise<Website> {
|
||||||
let website = null;
|
let website = null;
|
||||||
|
|
||||||
if (redisEnabled) {
|
try {
|
||||||
const redis = getClient();
|
if (redisEnabled) {
|
||||||
|
const redis = getClient();
|
||||||
|
|
||||||
website = await redis.fetch(`website:${websiteId}`, () => getWebsite(websiteId), 86400);
|
website = await redis.fetch(`website:${websiteId}`, () => getWebsite(websiteId), 86400);
|
||||||
} else {
|
} else {
|
||||||
website = await getWebsite(websiteId);
|
website = await getWebsite(websiteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!website || website.deletedAt) {
|
if (!website || website.deletedAt) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('FETCH WEBSITE ERROR:', serializeError(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
return website;
|
return website;
|
||||||
|
|
@ -23,16 +29,21 @@ export async function fetchWebsite(websiteId: string): Promise<Website> {
|
||||||
export async function fetchSession(websiteId: string, sessionId: string): Promise<Session> {
|
export async function fetchSession(websiteId: string, sessionId: string): Promise<Session> {
|
||||||
let session = null;
|
let session = null;
|
||||||
|
|
||||||
if (redisEnabled) {
|
try {
|
||||||
const redis = getClient();
|
if (redisEnabled) {
|
||||||
|
const redis = getClient();
|
||||||
|
|
||||||
session = await redis.fetch(
|
session = await redis.fetch(
|
||||||
`session:${sessionId}`,
|
`session:${sessionId}`,
|
||||||
() => getWebsiteSession(websiteId, sessionId),
|
() => getWebsiteSession(websiteId, sessionId),
|
||||||
86400,
|
86400,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
session = await getWebsiteSession(websiteId, sessionId);
|
session = await getWebsiteSession(websiteId, sessionId);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('FETCH SESSION ERROR:', serializeError(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue