mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 14:53:00 +03:00
fix: cache version information for 3 hours
This commit is contained in:
@@ -16,3 +16,9 @@ export type AppConfigRawResponse = {
|
||||
type: string;
|
||||
value: string;
|
||||
}[];
|
||||
|
||||
export type AppVersionInformation = {
|
||||
isUpToDate: boolean;
|
||||
newestVersion: string;
|
||||
currentVersion: string;
|
||||
};
|
||||
24
frontend/src/routes/settings/+layout.server.ts
Normal file
24
frontend/src/routes/settings/+layout.server.ts
Normal 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
|
||||
};
|
||||
};
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user