Skip to content

Commit 92e3210

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 452ba46 commit 92e3210

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
@@ -170,7 +170,7 @@ export const TsModsModule = {
170170
},
171171

172172
actions: <ActionTree<State, RootState>>{
173-
async fetchPackageListIndex({rootState}): Promise<PackageListIndex> {
173+
async fetchPackageListIndex({dispatch, rootState}): Promise<PackageListIndex> {
174174
const indexUrl = rootState.activeGame.thunderstoreUrl;
175175
const index = await retry(() => fetchAndProcessBlobFile(indexUrl));
176176

@@ -184,6 +184,13 @@ export const TsModsModule = {
184184
const community = rootState.activeGame.internalFolderName;
185185
const isLatest = await PackageDb.isLatestPackageListIndex(community, index.hash);
186186

187+
// Normally the hash would be updated after the mod list is successfully
188+
// fetched and written to IndexedDB, but if the list hasn't changed,
189+
// those step are skipped, so update the "last seen" timestamp now.
190+
if (isLatest) {
191+
await dispatch('updateIndexHash', index.hash);
192+
}
193+
187194
return {...index, isLatest};
188195
},
189196

@@ -230,13 +237,17 @@ export const TsModsModule = {
230237
commit('setExclusions', exclusions);
231238
},
232239

233-
async updateMods({commit, rootState}) {
240+
async updateMods({commit, dispatch, rootState}) {
234241
const modList = await PackageDb.getPackagesAsThunderstoreMods(rootState.activeGame.internalFolderName);
235-
const updated = await PackageDb.getLastPackageListUpdateTime(rootState.activeGame.internalFolderName);
236242
commit('setMods', modList);
237-
commit('setModsLastUpdated', updated);
238243
commit('updateDeprecated', modList);
239244
commit('clearModCache');
245+
await dispatch('updateModsLastUpdated');
246+
},
247+
248+
async updateModsLastUpdated({commit, rootState}) {
249+
const updated = await PackageDb.getLastPackageListUpdateTime(rootState.activeGame.internalFolderName);
250+
commit('setModsLastUpdated', updated);
240251
},
241252

242253
/*** Save a mod list received from the Thunderstore API to IndexedDB */
@@ -253,7 +264,12 @@ export const TsModsModule = {
253264
));
254265
const community = rootState.activeGame.internalFolderName;
255266
await PackageDb.updateFromApiResponse(community, filtered);
267+
await dispatch('updateIndexHash', indexHash);
268+
},
269+
270+
async updateIndexHash({rootState}, indexHash: string) {
271+
const community = rootState.activeGame.internalFolderName;
256272
await PackageDb.setLatestPackageListIndex(community, indexHash);
257-
}
273+
},
258274
}
259275
}

0 commit comments

Comments
 (0)