mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Updated queries to use cache.
This commit is contained in:
parent
74192cd695
commit
728e4cff5b
9 changed files with 59 additions and 42 deletions
34
lib/query.ts
34
lib/query.ts
|
|
@ -1,5 +1,5 @@
|
|||
import cache from 'lib/cache';
|
||||
import { getWebsite } from 'queries';
|
||||
import { getWebsite, getSession, getUser } from 'queries';
|
||||
import { Website } from './types';
|
||||
|
||||
export async function loadWebsite(websiteId: string): Promise<Website> {
|
||||
|
|
@ -17,3 +17,35 @@ export async function loadWebsite(websiteId: string): Promise<Website> {
|
|||
|
||||
return website;
|
||||
}
|
||||
|
||||
export async function loadSession(sessionId: string): Promise<Website> {
|
||||
let session;
|
||||
|
||||
if (cache.enabled) {
|
||||
session = await cache.fetchSession(sessionId);
|
||||
} else {
|
||||
session = await getSession({ id: sessionId });
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function loadUser(userId: string): Promise<Website> {
|
||||
let user;
|
||||
|
||||
if (cache.enabled) {
|
||||
user = await cache.fetchUser(userId);
|
||||
} else {
|
||||
user = await getUser({ id: userId });
|
||||
}
|
||||
|
||||
if (!user || user.deletedAt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue