mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 13:47:15 +01:00
Moved code into src folder. Added build for component library.
This commit is contained in:
parent
7a7233ead4
commit
ede658771e
490 changed files with 749 additions and 442 deletions
75
src/lib/cache.ts
Normal file
75
src/lib/cache.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import { User, Website } from '@prisma/client';
|
||||
import redis from '@umami/redis-client';
|
||||
import { getSession, getUserById, getWebsiteById } from '../queries';
|
||||
|
||||
const { fetchObject, storeObject, deleteObject } = redis;
|
||||
|
||||
async function fetchWebsite(id): Promise<Website> {
|
||||
return fetchObject(`website:${id}`, () => getWebsiteById(id));
|
||||
}
|
||||
|
||||
async function storeWebsite(data) {
|
||||
const { id } = data;
|
||||
const key = `website:${id}`;
|
||||
|
||||
return storeObject(key, data);
|
||||
}
|
||||
|
||||
async function deleteWebsite(id) {
|
||||
return deleteObject(`website:${id}`);
|
||||
}
|
||||
|
||||
async function fetchUser(id): Promise<User> {
|
||||
return fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }));
|
||||
}
|
||||
|
||||
async function storeUser(data) {
|
||||
const { id } = data;
|
||||
const key = `user:${id}`;
|
||||
|
||||
return storeObject(key, data);
|
||||
}
|
||||
|
||||
async function deleteUser(id) {
|
||||
return deleteObject(`user:${id}`);
|
||||
}
|
||||
|
||||
async function fetchSession(id) {
|
||||
return fetchObject(`session:${id}`, () => getSession(id));
|
||||
}
|
||||
|
||||
async function storeSession(data) {
|
||||
const { id } = data;
|
||||
const key = `session:${id}`;
|
||||
|
||||
return storeObject(key, data);
|
||||
}
|
||||
|
||||
async function deleteSession(id) {
|
||||
return deleteObject(`session:${id}`);
|
||||
}
|
||||
|
||||
async function fetchUserBlock(userId: string) {
|
||||
const key = `user:block:${userId}`;
|
||||
return redis.get(key);
|
||||
}
|
||||
|
||||
async function incrementUserBlock(userId: string) {
|
||||
const key = `user:block:${userId}`;
|
||||
return redis.incr(key);
|
||||
}
|
||||
|
||||
export default {
|
||||
fetchWebsite,
|
||||
storeWebsite,
|
||||
deleteWebsite,
|
||||
fetchUser,
|
||||
storeUser,
|
||||
deleteUser,
|
||||
fetchSession,
|
||||
storeSession,
|
||||
deleteSession,
|
||||
fetchUserBlock,
|
||||
incrementUserBlock,
|
||||
enabled: redis.enabled,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue