From e126952403da23ef17e5653ac8ece45df3a3d2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Fri, 26 Apr 2024 09:38:50 +0300 Subject: [PATCH 1/3] UtilityMixin: do route-based mod list update blocking earlier There seems to be no point in waiting to do this check, so do it as early as possible. This also makes the first function to only do the update and consolidates all the auxiliary stuff into the second function. --- src/components/mixins/UtilityMixin.vue | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/mixins/UtilityMixin.vue b/src/components/mixins/UtilityMixin.vue index 84e3911b..fad7d13b 100644 --- a/src/components/mixins/UtilityMixin.vue +++ b/src/components/mixins/UtilityMixin.vue @@ -16,15 +16,6 @@ export default class UtilityMixin extends Vue { } async refreshThunderstoreModList() { - // Don't do background update on index route since the game - // isn't really chosen yet, nor in the splash screen since it - // proactively updates the package list. - const exemptRoutes = ["index", "splash"]; - - if (this.$route.name && exemptRoutes.includes(this.$route.name)) { - return; - } - const response = await ConnectionProvider.instance.getPackages(this.$store.state.activeGame); await this.$store.dispatch("tsMods/updatePersistentCache", response.data); await this.$store.dispatch("tsMods/updateMods"); @@ -39,6 +30,15 @@ export default class UtilityMixin extends Vue { * failure to see how this affects the number of reported errors. */ private async tryRefreshThunderstoreModList() { + // Don't do background update on index route since the game + // isn't really chosen yet, nor in the splash screen since it + // proactively updates the package list. + const exemptRoutes = ["index", "splash"]; + + if (this.$route.name && exemptRoutes.includes(this.$route.name)) { + return; + } + try { await this.refreshThunderstoreModList(); } catch (e) { From 75a5bbcb12b37b9f52efda1b5bd857500b57d3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Fri, 26 Apr 2024 10:09:44 +0300 Subject: [PATCH 2/3] Prevent running multiple mod list background updates simultaneously 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. --- src/components/mixins/UtilityMixin.vue | 7 +++++++ src/store/modules/TsModsModule.ts | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/components/mixins/UtilityMixin.vue b/src/components/mixins/UtilityMixin.vue index fad7d13b..3571e19a 100644 --- a/src/components/mixins/UtilityMixin.vue +++ b/src/components/mixins/UtilityMixin.vue @@ -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) { @@ -49,6 +54,8 @@ export default class UtilityMixin extends Vue { this.tsRefreshFailed = true; return; + } finally { + this.$store.commit("tsMods/finishBackgroundUpdate"); } this.tsRefreshFailed = false; diff --git a/src/store/modules/TsModsModule.ts b/src/store/modules/TsModsModule.ts index 576bbdd6..6396e8aa 100644 --- a/src/store/modules/TsModsModule.ts +++ b/src/store/modules/TsModsModule.ts @@ -18,6 +18,7 @@ interface State { connectionError: string; deprecated: Map; exclusions?: string[]; + isBackgroundUpdateInProgress: boolean; mods: ThunderstoreMod[]; modsLastUpdated?: Date; } @@ -38,6 +39,8 @@ export const TsModsModule = { deprecated: new Map(), /*** 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? */ @@ -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; @@ -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); } From 13a9873e91a2b614b88392cb92503e8ff9073d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Fri, 26 Apr 2024 10:16:03 +0300 Subject: [PATCH 3/3] Prevent manual and automatic mod list updates running simultaneously Users can trigger updating the online mod list from the settings view. Use the status text to show if an update is already in progress and prevent user actions from triggering another one, since they would just compete for the same bandwidth and slow down the manager. --- .../settings-components/SettingsView.vue | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/settings-components/SettingsView.vue b/src/components/settings-components/SettingsView.vue index 5e76b764..637aead4 100644 --- a/src/components/settings-components/SettingsView.vue +++ b/src/components/settings-components/SettingsView.vue @@ -78,7 +78,6 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; private search: string = ''; private managerVersionNumber: VersionNumber = ManagerInformation.VERSION; private searchableSettings: SettingsRow[] = []; - private downloadingThunderstoreModList: boolean = false; get activeGame(): Game { return this.$store.state.activeGame; @@ -299,7 +298,7 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; 'Refresh online mod list', 'Check for any new mod releases.', async () => { - if (this.downloadingThunderstoreModList) { + if (this.$store.state.tsMods.isBackgroundUpdateInProgress) { return "Checking for new releases"; } if (this.$store.state.tsMods.connectionError.length > 0) { @@ -312,17 +311,19 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; }, 'fa-exchange-alt', async () => { - if (!this.downloadingThunderstoreModList) { - this.downloadingThunderstoreModList = true; - this.$store.commit("tsMods/setConnectionError", ""); + if (this.$store.state.tsMods.isBackgroundUpdateInProgress) { + return; + } - try { - await this.refreshThunderstoreModList(); - } catch (e) { - this.$store.commit("tsMods/setConnectionError", e); - } finally { - this.downloadingThunderstoreModList = false; - } + this.$store.commit("tsMods/startBackgroundUpdate"); + this.$store.commit("tsMods/setConnectionError", ""); + + try { + await this.refreshThunderstoreModList(); + } catch (e) { + this.$store.commit("tsMods/setConnectionError", e); + } finally { + this.$store.commit("tsMods/finishBackgroundUpdate"); } } ),