Skip to content

Commit

Permalink
Prevent running multiple mod list background updates simultaneously
Browse files Browse the repository at this point in the history
Online mod list is currently updated on the background every 5 minutes.
Ideally downloading and processing the mod list wouldn't take that long
that the interval would fire before an earlier round has finished, but
the most popular games have so many mods that on people with slower
connections this seems to happen. Multiple connections then compete for
the same download bandwidth, making the process even slower.
  • Loading branch information
anttimaki committed Apr 26, 2024
1 parent e126952 commit 75a5bbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/mixins/UtilityMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export default class UtilityMixin extends Vue {
return;
}
if (this.$store.state.tsMods.isBackgroundUpdateInProgress) {
return;
}
try {
this.$store.commit("tsMods/startBackgroundUpdate");
await this.refreshThunderstoreModList();
} catch (e) {
if (this.tsRefreshFailed) {
Expand All @@ -49,6 +54,8 @@ export default class UtilityMixin extends Vue {
this.tsRefreshFailed = true;
return;
} finally {
this.$store.commit("tsMods/finishBackgroundUpdate");
}
this.tsRefreshFailed = false;
Expand Down
9 changes: 9 additions & 0 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface State {
connectionError: string;
deprecated: Map<string, boolean>;
exclusions?: string[];
isBackgroundUpdateInProgress: boolean;
mods: ThunderstoreMod[];
modsLastUpdated?: Date;
}
Expand All @@ -38,6 +39,8 @@ export const TsModsModule = {
deprecated: new Map<string, boolean>(),
/*** Packages available through API that should be ignored by the manager */
exclusions: [],
/*** Mod list is automatically and periodically updated in the background */
isBackgroundUpdateInProgress: false,
/*** All mods available through API for the current active game */
mods: [],
/*** When was the mod list last refreshed from the API? */
Expand Down Expand Up @@ -116,6 +119,9 @@ export const TsModsModule = {
clearModCache(state) {
state.cache.clear();
},
finishBackgroundUpdate(state) {
state.isBackgroundUpdateInProgress = false;
},
setConnectionError(state, error: string|unknown) {
if (typeof error === 'string') {
state.connectionError = error;
Expand All @@ -133,6 +139,9 @@ export const TsModsModule = {
setExclusions(state, payload: string[]) {
state.exclusions = payload;
},
startBackgroundUpdate(state) {
state.isBackgroundUpdateInProgress = true;
},
updateDeprecated(state, allMods: ThunderstoreMod[]) {
state.deprecated = Deprecations.getDeprecatedPackageMap(allMods);
}
Expand Down

0 comments on commit 75a5bbc

Please sign in to comment.