From b44ae70321d85f1363371e7a4390441249eea67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Thu, 16 Jan 2025 11:51:38 +0200 Subject: [PATCH] Cache whether the active game has a package list in IndexedDB SettingRow items update their value for on one second interval. While reading the status from IndexedDB isn't a noticeable performance hit (at least on my PC), it becomes an issue if checking the status throws an error. In those cases TSMM's Sentry gets bombarded with an error every second users stays on the settings screen. Cache invalidation obviously makes the implementation more complex. The cache can still show incorrect values if user manually deletes the entries from IndexedDB via dev tools but that's acceptable. --- src/store/modules/TsModsModule.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/store/modules/TsModsModule.ts b/src/store/modules/TsModsModule.ts index 42018c5ea..d0315cf61 100644 --- a/src/store/modules/TsModsModule.ts +++ b/src/store/modules/TsModsModule.ts @@ -18,6 +18,7 @@ export interface CachedMod { } interface State { + activeGameCacheStatus: string|undefined; cache: Map; deprecated: Map; exclusions: string[]; @@ -55,6 +56,8 @@ export const TsModsModule = { namespaced: true, state: (): State => ({ + /*** Does the active game have a mod list stored in IndexedDB? */ + activeGameCacheStatus: undefined, cache: new Map(), deprecated: new Map(), /*** Packages available through API that should be ignored by the manager */ @@ -127,6 +130,7 @@ export const TsModsModule = { mutations: >{ reset(state: State) { + state.activeGameCacheStatus = undefined; state.cache = new Map(); state.deprecated = new Map(); state.mods = []; @@ -141,6 +145,9 @@ export const TsModsModule = { state.isThunderstoreModListUpdateInProgress = false; state.thunderstoreModListUpdateStatus = ''; }, + setActiveGameCacheStatus(state, status: string|undefined) { + state.activeGameCacheStatus = status; + }, setMods(state, payload: ThunderstoreMod[]) { state.mods = payload; }, @@ -222,6 +229,7 @@ export const TsModsModule = { } catch (e) { commit('setThunderstoreModListUpdateError', e); } finally { + commit('setActiveGameCacheStatus', undefined); commit('finishThunderstoreModListUpdate'); } }, @@ -293,14 +301,28 @@ export const TsModsModule = { return updated !== undefined; }, - async getActiveGameCacheStatus({state, rootState}) { + async getActiveGameCacheStatus({commit, state, rootState}): Promise { if (state.isThunderstoreModListUpdateInProgress) { return "Online mod list is currently updating, please wait for the operation to complete"; } - return (await PackageDb.hasEntries(rootState.activeGame.internalFolderName)) - ? `${rootState.activeGame.displayName} has a local copy of online mod list` - : `${rootState.activeGame.displayName} has no local copy stored`; + // Only check the status once, as this is used in the settings + // where the value is polled on one second intervals. + if (state.activeGameCacheStatus === undefined) { + let status = ''; + try { + status = (await PackageDb.hasEntries(rootState.activeGame.internalFolderName)) + ? `${rootState.activeGame.displayName} has a local copy of online mod list` + : `${rootState.activeGame.displayName} has no local copy stored`; + } catch (e) { + console.error(e); + status = 'Error occurred while checking mod list status'; + } + + commit('setActiveGameCacheStatus', status); + } + + return state.activeGameCacheStatus || 'Unknown status'; }, async prewarmCache({getters, rootGetters}) { @@ -326,6 +348,7 @@ export const TsModsModule = { await PackageDb.resetCommunity(community); commit('setModsLastUpdated', undefined); } finally { + commit('setActiveGameCacheStatus', undefined); commit('finishThunderstoreModListUpdate'); } },