Skip to content

Commit

Permalink
Merge pull request #1311 from ebkr/utility-mixin-fixin
Browse files Browse the repository at this point in the history
Prevent multiple simultaneous package list updates
  • Loading branch information
anttimaki authored Apr 29, 2024
2 parents b1c3ec1 + 13a9873 commit 4cd8d14
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
25 changes: 16 additions & 9 deletions src/components/mixins/UtilityMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -39,7 +30,21 @@ 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;
}
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
25 changes: 13 additions & 12 deletions src/components/settings-components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
}
}
),
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 4cd8d14

Please sign in to comment.