mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Updated prisma and redis clients.
This commit is contained in:
parent
c05d116875
commit
dff105c747
9 changed files with 40 additions and 125 deletions
14
lib/cache.ts
14
lib/cache.ts
|
|
@ -1,10 +1,16 @@
|
|||
import { User, Website } from '@prisma/client';
|
||||
import redis from 'lib/redis';
|
||||
import redis from '@umami/redis-client';
|
||||
import { getSession, getUser, getWebsite } from '../queries';
|
||||
|
||||
const DELETED = 'DELETED';
|
||||
|
||||
async function fetchObject(key, query) {
|
||||
const obj = await redis.get(key);
|
||||
|
||||
if (obj === DELETED) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!obj) {
|
||||
return query().then(async data => {
|
||||
if (data) {
|
||||
|
|
@ -22,8 +28,8 @@ async function storeObject(key, data) {
|
|||
return redis.set(key, data);
|
||||
}
|
||||
|
||||
async function deleteObject(key) {
|
||||
return redis.set(key, redis.DELETED);
|
||||
async function deleteObject(key, soft = false) {
|
||||
return soft ? redis.set(key, DELETED) : redis.del(key);
|
||||
}
|
||||
|
||||
async function fetchWebsite(id): Promise<Website> {
|
||||
|
|
@ -42,7 +48,7 @@ async function deleteWebsite(id) {
|
|||
}
|
||||
|
||||
async function fetchUser(id): Promise<User> {
|
||||
return fetchObject(`user:${id}`, () => getUser({ id }, true));
|
||||
return fetchObject(`user:${id}`, () => getUser({ id }, { includePassword: true }));
|
||||
}
|
||||
|
||||
async function storeUser(data) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue