Skip to content

Commit 4c8f91c

Browse files
authored
Merge pull request #1619 from ebkr/cache-reset-improvements
Improve "reset cached package list" feature
2 parents 669d972 + b44ae70 commit 4c8f91c

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

Diff for: src/store/modules/TsModsModule.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface CachedMod {
1818
}
1919

2020
interface State {
21+
activeGameCacheStatus: string|undefined;
2122
cache: Map<string, CachedMod>;
2223
deprecated: Map<string, boolean>;
2324
exclusions: string[];
@@ -55,6 +56,8 @@ export const TsModsModule = {
5556
namespaced: true,
5657

5758
state: (): State => ({
59+
/*** Does the active game have a mod list stored in IndexedDB? */
60+
activeGameCacheStatus: undefined,
5861
cache: new Map<string, CachedMod>(),
5962
deprecated: new Map<string, boolean>(),
6063
/*** Packages available through API that should be ignored by the manager */
@@ -127,6 +130,7 @@ export const TsModsModule = {
127130

128131
mutations: <MutationTree<State>>{
129132
reset(state: State) {
133+
state.activeGameCacheStatus = undefined;
130134
state.cache = new Map<string, CachedMod>();
131135
state.deprecated = new Map<string, boolean>();
132136
state.mods = [];
@@ -141,6 +145,9 @@ export const TsModsModule = {
141145
state.isThunderstoreModListUpdateInProgress = false;
142146
state.thunderstoreModListUpdateStatus = '';
143147
},
148+
setActiveGameCacheStatus(state, status: string|undefined) {
149+
state.activeGameCacheStatus = status;
150+
},
144151
setMods(state, payload: ThunderstoreMod[]) {
145152
state.mods = payload;
146153
},
@@ -222,6 +229,7 @@ export const TsModsModule = {
222229
} catch (e) {
223230
commit('setThunderstoreModListUpdateError', e);
224231
} finally {
232+
commit('setActiveGameCacheStatus', undefined);
225233
commit('finishThunderstoreModListUpdate');
226234
}
227235
},
@@ -293,14 +301,28 @@ export const TsModsModule = {
293301
return updated !== undefined;
294302
},
295303

296-
async getActiveGameCacheStatus({state, rootState}) {
304+
async getActiveGameCacheStatus({commit, state, rootState}): Promise<string> {
297305
if (state.isThunderstoreModListUpdateInProgress) {
298306
return "Online mod list is currently updating, please wait for the operation to complete";
299307
}
300308

301-
return (await PackageDb.hasEntries(rootState.activeGame.internalFolderName))
302-
? `${rootState.activeGame.displayName} has a local copy of online mod list`
303-
: `${rootState.activeGame.displayName} has no local copy stored`;
309+
// Only check the status once, as this is used in the settings
310+
// where the value is polled on one second intervals.
311+
if (state.activeGameCacheStatus === undefined) {
312+
let status = '';
313+
try {
314+
status = (await PackageDb.hasEntries(rootState.activeGame.internalFolderName))
315+
? `${rootState.activeGame.displayName} has a local copy of online mod list`
316+
: `${rootState.activeGame.displayName} has no local copy stored`;
317+
} catch (e) {
318+
console.error(e);
319+
status = 'Error occurred while checking mod list status';
320+
}
321+
322+
commit('setActiveGameCacheStatus', status);
323+
}
324+
325+
return state.activeGameCacheStatus || 'Unknown status';
304326
},
305327

306328
async prewarmCache({getters, rootGetters}) {
@@ -324,7 +346,9 @@ export const TsModsModule = {
324346
try {
325347
commit('setThunderstoreModListUpdateStatus', 'Resetting mod list cache...');
326348
await PackageDb.resetCommunity(community);
349+
commit('setModsLastUpdated', undefined);
327350
} finally {
351+
commit('setActiveGameCacheStatus', undefined);
328352
commit('finishThunderstoreModListUpdate');
329353
}
330354
},

0 commit comments

Comments
 (0)