Skip to content

Commit

Permalink
fix: cache version information for 3 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 23, 2024
1 parent 2092007 commit 29d632c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions frontend/src/lib/types/application-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ export type AppConfigRawResponse = {
type: string;
value: string;
}[];

export type AppVersionInformation = {
isUpToDate: boolean;
newestVersion: string;
currentVersion: string;
};
24 changes: 24 additions & 0 deletions frontend/src/routes/settings/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -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
};
};
11 changes: 0 additions & 11 deletions frontend/src/routes/settings/+layout.ts

This file was deleted.

0 comments on commit 29d632c

Please sign in to comment.