Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple simultaneous package list updates #1311

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading