fix: cache version information for 3 hours

This commit is contained in:
Elias Schneider
2024-10-23 11:48:46 +02:00
parent 2092007752
commit 29d632c151
3 changed files with 30 additions and 11 deletions

View File

@@ -16,3 +16,9 @@ export type AppConfigRawResponse = {
type: string;
value: string;
}[];
export type AppVersionInformation = {
isUpToDate: boolean;
newestVersion: string;
currentVersion: string;
};

View File

@@ -0,0 +1,24 @@
import AppConfigService from '$lib/services/app-config-service';
import type { AppVersionInformation } from '$lib/types/application-configuration';
import type { LayoutServerLoad } from './$types';
let versionInformation: AppVersionInformation;
let versionInformationLastUpdated: number;
export const load: LayoutServerLoad = async () => {
const appConfigService = new AppConfigService();
// Cache the version information for 3 hours
const cacheExpired =
versionInformationLastUpdated &&
Date.now() - versionInformationLastUpdated > 1000 * 60 * 60 * 3;
if (!versionInformation || cacheExpired) {
versionInformation = await appConfigService.getVersionInformation();
versionInformationLastUpdated = Date.now();
}
return {
versionInformation
};
};

View File

@@ -1,11 +0,0 @@
import AppConfigService from '$lib/services/app-config-service';
import type { LayoutLoad } from './$types';
export const load: LayoutLoad = async () => {
const appConfigService = new AppConfigService();
const versionInformation = await appConfigService.getVersionInformation();
return {
versionInformation
};
};