From 0157450425dce2e71dd33d70822d5147adbd63a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 23 Dec 2024 11:18:12 +0200 Subject: [PATCH] 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. --- .../settings-components/SettingsView.vue | 8 ++++++ src/r2mm/manager/PackageDexieStore.ts | 20 ++++++++++++++ src/store/modules/TsModsModule.ts | 26 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/src/components/settings-components/SettingsView.vue b/src/components/settings-components/SettingsView.vue index be50a4328..df0d6115f 100644 --- a/src/components/settings-components/SettingsView.vue +++ b/src/components/settings-components/SettingsView.vue @@ -185,6 +185,14 @@ import CdnProvider from '../../providers/generic/connection/CdnProvider'; 'fa-trash', () => this.emitInvoke('CleanCache') ), + new SettingsRow( + 'Debugging', + 'Clean online mod list', + 'Deletes local copy of mod list, forcing the next refresh to fetch a new one.', + async () => this.$store.dispatch('tsMods/getActiveGameCacheStatus'), + 'fa-trash', + () => this.$store.dispatch('tsMods/resetActiveGameCache') + ), new SettingsRow( 'Debugging', 'Toggle preferred Thunderstore CDN', diff --git a/src/r2mm/manager/PackageDexieStore.ts b/src/r2mm/manager/PackageDexieStore.ts index 216209ff5..c870a267e 100644 --- a/src/r2mm/manager/PackageDexieStore.ts +++ b/src/r2mm/manager/PackageDexieStore.ts @@ -141,6 +141,18 @@ export async function getVersionAsThunderstoreVersion(community: string, package return ThunderstoreVersion.parseFromThunderstoreData(version); } +export async function hasEntries(community: string): Promise { + if (await db.indexHashes.where({community}).count()) { + return true; + } + + if (await db.packages.where({community}).count()) { + return true; + } + + return false; +} + export async function isLatestPackageListIndex(community: string, hash: string) { return Boolean( await db.indexHashes.where({community, hash}).count() @@ -159,6 +171,14 @@ export async function pruneRemovedMods(community: string, cutoff: Date) { await db.packages.bulkDelete(oldIds); } +export async function resetCommunity(community: string) { + await db.transaction('rw', db.packages, db.indexHashes, async () => { + const packageIds = await db.packages.where({community}).primaryKeys(); + await db.packages.bulkDelete(packageIds); + await db.indexHashes.where({community}).delete(); + }); +} + export async function upsertPackageListChunk(community: string, packageChunk: any[]) { const extra = {community, date_fetched: new Date()}; const newPackages: DexiePackage[] = packageChunk.map((pkg) => ({...pkg, ...extra})); diff --git a/src/store/modules/TsModsModule.ts b/src/store/modules/TsModsModule.ts index 3a2978e22..9318512e7 100644 --- a/src/store/modules/TsModsModule.ts +++ b/src/store/modules/TsModsModule.ts @@ -293,6 +293,16 @@ export const TsModsModule = { return updated !== undefined; }, + async getActiveGameCacheStatus({state, rootState}) { + 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`; + }, + async prewarmCache({getters, rootGetters}) { const profileMods: ManifestV2[] = rootGetters['profile/modList']; profileMods.forEach(getters['cachedMod']); @@ -303,6 +313,22 @@ export const TsModsModule = { await PackageDb.pruneRemovedMods(community, cutoff); }, + async resetActiveGameCache({commit, rootState, state}) { + if (state.isThunderstoreModListUpdateInProgress) { + return; + } + + commit('startThunderstoreModListUpdate'); + const community = rootState.activeGame.internalFolderName; + + try { + commit('setThunderstoreModListUpdateStatus', 'Resetting mod list cache...'); + await PackageDb.resetCommunity(community); + } finally { + commit('finishThunderstoreModListUpdate'); + } + }, + async updateExclusions({commit}) { // Read exclusion list from a bundled file to have some values available ASAP. const exclusionList: {exclusions: string[]} = require('../../../modExclusions.json');