make status api faster

This commit is contained in:
Akis 2023-01-03 11:38:55 +02:00
parent 27269d2476
commit b812dabed5
Signed by untrusted user: akis
GPG Key ID: 267BF5C6677944ED
4 changed files with 18 additions and 15 deletions

View File

@ -1,6 +1,8 @@
import { SvelteKitAuth } from "@auth/sveltekit"
import Authentik from '@auth/core/providers/authentik';
import { env } from "$env/dynamic/private";
import statusData from "$lib/statusData";
import map from "$lib/map";
export const handle = SvelteKitAuth({
providers: [
@ -11,4 +13,15 @@ export const handle = SvelteKitAuth({
issuer: env.AUTH_ISSUER
})
]
})
})
const updateMap = () => {
map.set("data", {
status: statusData,
updated: Math.floor(Date.now() / 1000)
});
};
updateMap();
setInterval(updateMap, 30000);

3
src/lib/map.ts Normal file
View File

@ -0,0 +1,3 @@
const map = new Map();
export default map;

View File

@ -1,18 +1,5 @@
import type { RequestHandler } from './$types';
import statusData from "./statusData";
const map = new Map();
const updateMap = () => {
map.set("data", {
status: statusData,
updated: Math.floor(Date.now() / 1000)
});
};
updateMap();
setInterval(updateMap, 60000);
import map from "$lib/map";
export const GET = (() => {
const data = map.get("data");