Skip to content

Commit

Permalink
Merge pull request #1602 from ebkr/package-db-reset
Browse files Browse the repository at this point in the history
Add setting for resetting online mod list stored in IndexedDB
  • Loading branch information
anttimaki authored Jan 15, 2025
2 parents af87843 + 0157450 commit bf235bb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/settings-components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 20 additions & 0 deletions src/r2mm/manager/PackageDexieStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ export async function getVersionAsThunderstoreVersion(community: string, package
return ThunderstoreVersion.parseFromThunderstoreData(version);
}

export async function hasEntries(community: string): Promise<boolean> {
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()
Expand All @@ -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}));
Expand Down
26 changes: 26 additions & 0 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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');
Expand Down

0 comments on commit bf235bb

Please sign in to comment.