Skip to content

Commit 0157450

Browse files
committed
Add setting for resetting online mod list stored in IndexedDB
This debug option can be used if the mod list stored in IndexedDB is corrupted, preventing it from being loaded into Vuex. Otherwise user would have to wait for a new version of the mod list to be available on Thunderstore API and hoping the update fixes the issue.
1 parent d993434 commit 0157450

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Diff for: src/components/settings-components/SettingsView.vue

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ import CdnProvider from '../../providers/generic/connection/CdnProvider';
185185
'fa-trash',
186186
() => this.emitInvoke('CleanCache')
187187
),
188+
new SettingsRow(
189+
'Debugging',
190+
'Clean online mod list',
191+
'Deletes local copy of mod list, forcing the next refresh to fetch a new one.',
192+
async () => this.$store.dispatch('tsMods/getActiveGameCacheStatus'),
193+
'fa-trash',
194+
() => this.$store.dispatch('tsMods/resetActiveGameCache')
195+
),
188196
new SettingsRow(
189197
'Debugging',
190198
'Toggle preferred Thunderstore CDN',

Diff for: src/r2mm/manager/PackageDexieStore.ts

+20
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ export async function getVersionAsThunderstoreVersion(community: string, package
141141
return ThunderstoreVersion.parseFromThunderstoreData(version);
142142
}
143143

144+
export async function hasEntries(community: string): Promise<boolean> {
145+
if (await db.indexHashes.where({community}).count()) {
146+
return true;
147+
}
148+
149+
if (await db.packages.where({community}).count()) {
150+
return true;
151+
}
152+
153+
return false;
154+
}
155+
144156
export async function isLatestPackageListIndex(community: string, hash: string) {
145157
return Boolean(
146158
await db.indexHashes.where({community, hash}).count()
@@ -159,6 +171,14 @@ export async function pruneRemovedMods(community: string, cutoff: Date) {
159171
await db.packages.bulkDelete(oldIds);
160172
}
161173

174+
export async function resetCommunity(community: string) {
175+
await db.transaction('rw', db.packages, db.indexHashes, async () => {
176+
const packageIds = await db.packages.where({community}).primaryKeys();
177+
await db.packages.bulkDelete(packageIds);
178+
await db.indexHashes.where({community}).delete();
179+
});
180+
}
181+
162182
export async function upsertPackageListChunk(community: string, packageChunk: any[]) {
163183
const extra = {community, date_fetched: new Date()};
164184
const newPackages: DexiePackage[] = packageChunk.map((pkg) => ({...pkg, ...extra}));

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

+26
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ export const TsModsModule = {
293293
return updated !== undefined;
294294
},
295295

296+
async getActiveGameCacheStatus({state, rootState}) {
297+
if (state.isThunderstoreModListUpdateInProgress) {
298+
return "Online mod list is currently updating, please wait for the operation to complete";
299+
}
300+
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`;
304+
},
305+
296306
async prewarmCache({getters, rootGetters}) {
297307
const profileMods: ManifestV2[] = rootGetters['profile/modList'];
298308
profileMods.forEach(getters['cachedMod']);
@@ -303,6 +313,22 @@ export const TsModsModule = {
303313
await PackageDb.pruneRemovedMods(community, cutoff);
304314
},
305315

316+
async resetActiveGameCache({commit, rootState, state}) {
317+
if (state.isThunderstoreModListUpdateInProgress) {
318+
return;
319+
}
320+
321+
commit('startThunderstoreModListUpdate');
322+
const community = rootState.activeGame.internalFolderName;
323+
324+
try {
325+
commit('setThunderstoreModListUpdateStatus', 'Resetting mod list cache...');
326+
await PackageDb.resetCommunity(community);
327+
} finally {
328+
commit('finishThunderstoreModListUpdate');
329+
}
330+
},
331+
306332
async updateExclusions({commit}) {
307333
// Read exclusion list from a bundled file to have some values available ASAP.
308334
const exclusionList: {exclusions: string[]} = require('../../../modExclusions.json');

0 commit comments

Comments
 (0)