From b812dabed561425b0488dc780aef5f053125d3a3 Mon Sep 17 00:00:00 2001 From: Akis Date: Tue, 3 Jan 2023 11:38:55 +0200 Subject: [PATCH] make status api faster --- src/hooks.server.ts | 15 ++++++++++++++- src/lib/map.ts | 3 +++ src/{routes/api/status => lib}/statusData.ts | 0 src/routes/api/status/+server.ts | 15 +-------------- 4 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 src/lib/map.ts rename src/{routes/api/status => lib}/statusData.ts (100%) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index ef25271..cf83495 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -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 }) ] -}) \ No newline at end of file +}) + +const updateMap = () => { + map.set("data", { + status: statusData, + updated: Math.floor(Date.now() / 1000) + }); +}; + +updateMap(); + +setInterval(updateMap, 30000); \ No newline at end of file diff --git a/src/lib/map.ts b/src/lib/map.ts new file mode 100644 index 0000000..1a61bff --- /dev/null +++ b/src/lib/map.ts @@ -0,0 +1,3 @@ +const map = new Map(); + +export default map; \ No newline at end of file diff --git a/src/routes/api/status/statusData.ts b/src/lib/statusData.ts similarity index 100% rename from src/routes/api/status/statusData.ts rename to src/lib/statusData.ts diff --git a/src/routes/api/status/+server.ts b/src/routes/api/status/+server.ts index 98464b9..f6ac558 100644 --- a/src/routes/api/status/+server.ts +++ b/src/routes/api/status/+server.ts @@ -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");