Skip to content

Commit d4c5311

Browse files
committed
Change where and how the "mods last updated" timestamp is updated
Old approach used to read the timestamp from the package list table since it wasn't available elsewhere. This approach no longer works when we don't update the package list into database if it didn't change. Instead, store the information in the same table as the community's last seen index chunk hash. This timestamp is updated whenever the same index hash is seen again, or when the hash changes AND the new package list is successfully written to DB. Old approach loaded the timestamp into Vuex when the package list was read to Vuex state. With the new approach we need to take into account that UtilityMixin skips updating the package list in memory if the list didn't change. Instead, we need to update the timestamp manually.
1 parent fb41f15 commit d4c5311

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

src/components/mixins/UtilityMixin.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class UtilityMixin extends Vue {
1919
const packageListIndex: PackageListIndex = await this.$store.dispatch("tsMods/fetchPackageListIndex");
2020
2121
if (packageListIndex.isLatest) {
22+
await this.$store.dispatch("tsMods/updateModsLastUpdated");
2223
return;
2324
}
2425

src/r2mm/manager/PackageDexieStore.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,9 @@ export async function getPackagesByNames(community: string, packageNames: string
123123
return packages.map(ThunderstoreMod.parseFromThunderstoreData);
124124
}
125125

126-
// TODO: Dexie v3 doesn't support combining .where() and .orderBy() in a
127-
// way that would utilize the DB indexes. The current implementation
128-
// bypasses this by assuming that outside the updateFromApiResponse
129-
// transaction, all the packages have the same date_fetched value.
130-
// Moving to Dexie v4 might improve things, but if that doesn't turn out
131-
// to be true, filter or order the result set on JS side instead.
132126
export async function getLastPackageListUpdateTime(community: string) {
133-
const fetched = await db.packages
134-
.where('[community+date_fetched]')
135-
.between([community, Dexie.minKey], [community, Dexie.maxKey])
136-
.first();
137-
138-
return fetched ? fetched.date_fetched : undefined;
127+
const hash = await db.indexHashes.where({community}).first();
128+
return hash ? hash.date_updated : undefined;
139129
}
140130

141131
export async function isLatestPackageListIndex(community: string, hash: string) {

src/store/modules/TsModsModule.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const TsModsModule = {
162162
},
163163

164164
actions: <ActionTree<State, RootState>>{
165-
async fetchPackageListIndex({rootState}): Promise<PackageListIndex> {
165+
async fetchPackageListIndex({dispatch, rootState}): Promise<PackageListIndex> {
166166
const indexUrl = rootState.activeGame.thunderstoreUrl;
167167
const index = await retry(() => fetchAndProcessBlobFile(indexUrl));
168168

@@ -176,6 +176,13 @@ export const TsModsModule = {
176176
const community = rootState.activeGame.internalFolderName;
177177
const isLatest = await PackageDb.isLatestPackageListIndex(community, index.hash);
178178

179+
// Normally the hash would be updated after the mod list is successfully
180+
// fetched and written to IndexedDB, but if the list hasn't changed,
181+
// those step are skipped, so update the "last seen" timestamp now.
182+
if (isLatest) {
183+
await dispatch('updateIndexHash', index.hash);
184+
}
185+
179186
return {...index, isLatest};
180187
},
181188

@@ -222,13 +229,17 @@ export const TsModsModule = {
222229
commit('setExclusions', exclusions);
223230
},
224231

225-
async updateMods({commit, rootState}) {
232+
async updateMods({commit, dispatch, rootState}) {
226233
const modList = await PackageDb.getPackagesAsThunderstoreMods(rootState.activeGame.internalFolderName);
227-
const updated = await PackageDb.getLastPackageListUpdateTime(rootState.activeGame.internalFolderName);
228234
commit('setMods', modList);
229-
commit('setModsLastUpdated', updated);
230235
commit('updateDeprecated', modList);
231236
commit('clearModCache');
237+
await dispatch('updateModsLastUpdated');
238+
},
239+
240+
async updateModsLastUpdated({commit, rootState}) {
241+
const updated = await PackageDb.getLastPackageListUpdateTime(rootState.activeGame.internalFolderName);
242+
commit('setModsLastUpdated', updated);
232243
},
233244

234245
/*** Save a mod list received from the Thunderstore API to IndexedDB */
@@ -245,7 +256,12 @@ export const TsModsModule = {
245256
));
246257
const community = rootState.activeGame.internalFolderName;
247258
await PackageDb.updateFromApiResponse(community, filtered);
259+
await dispatch('updateIndexHash', indexHash);
260+
},
261+
262+
async updateIndexHash({rootState}, indexHash: string) {
263+
const community = rootState.activeGame.internalFolderName;
248264
await PackageDb.setLatestPackageListIndex(community, indexHash);
249-
}
265+
},
250266
}
251267
}

0 commit comments

Comments
 (0)