mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
Updated redis client. Soft deletes reset username.
This commit is contained in:
parent
37b94e5b96
commit
e92d958b24
6 changed files with 11 additions and 37 deletions
30
lib/cache.ts
30
lib/cache.ts
|
|
@ -2,35 +2,7 @@ import { User, Website } from '@prisma/client';
|
|||
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) {
|
||||
await redis.set(key, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
async function storeObject(key, data) {
|
||||
return redis.set(key, data);
|
||||
}
|
||||
|
||||
async function deleteObject(key, soft = false) {
|
||||
return soft ? redis.set(key, DELETED) : redis.del(key);
|
||||
}
|
||||
const { fetchObject, storeObject, deleteObject } = redis;
|
||||
|
||||
async function fetchWebsite(id): Promise<Website> {
|
||||
return fetchObject(`website:${id}`, () => getWebsite({ id }));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue