improve update logic

This commit is contained in:
Matthias 2021-09-02 07:02:46 +02:00
parent 8b7d79162d
commit c762009a6f
3 changed files with 12 additions and 22 deletions

View File

@ -1,6 +1,6 @@
<template>
<div class="d-flex flex-align-center">
<b-button class="m-1 mr-3" variant="secondary" size="sm" @click="refreshFull(true)">
<b-button class="m-1 mr-3" variant="secondary" size="sm" @click="allRefreshFull(true)">
<RefreshIcon :size="16" />
</b-button>
@ -50,13 +50,7 @@ export default class ReloadControl extends Vue {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action setAutoRefresh!: (newValue: boolean) => void;
@ftbot.Action refreshFull;
@ftbot.Action refreshOnce;
@ftbot.Action startRefresh;
@ftbot.Action stopRefresh;
@ftbot.Action allRefreshFull;
get autoRefreshLoc() {
return this.autoRefresh;

View File

@ -145,10 +145,7 @@ export default function createBotStore(store) {
allRefreshFrequent({ dispatch, getters }, slow: boolean) {
console.log('dispatching all frequent refreshes');
getters.allAvailableBotsList.forEach((e) => {
if (
getters[`${e}/${BotStoreGetters.autoRefresh}`] &&
getters[`${e}/${BotStoreGetters.isBotOnline}`]
) {
if (getters[`${e}/${BotStoreGetters.refreshNow}`]) {
// console.log('refreshing', e);
dispatch(`${e}/${BotStoreActions.refreshFrequent}`, slow);
}
@ -157,25 +154,24 @@ export default function createBotStore(store) {
allRefreshSlow({ dispatch, getters }) {
console.log('dispatching all slow refreshes');
getters.allAvailableBotsList.forEach((e) => {
if (
getters[`${e}/${BotStoreGetters.autoRefresh}`] &&
getters[`${e}/${BotStoreGetters.isBotOnline}`]
) {
if (getters[`${e}/${BotStoreGetters.refreshNow}`]) {
dispatch(`${e}/${BotStoreActions.refreshSlow}`);
}
});
},
async refreshxxFull({ commit, dispatch, getters, state }, forceUpdate = false) {
async allRefreshFull({ commit, dispatch, state }, forceUpdate = false) {
if (state.refreshing) {
return;
}
commit('setRefreshing', true);
try {
// Ensure all bots status is correct.
await dispatch('pingAll');
const updates: Promise<AxiosInstance>[] = [];
updates.push(dispatch('refreshFrequent', false));
updates.push(dispatch('refreshSlow', forceUpdate));
updates.push(dispatch('getDaily'));
updates.push(dispatch('getBalance'));
updates.push(dispatch('allRefreshFrequent', false));
updates.push(dispatch('allRefreshSlow'));
// updates.push(dispatch('getDaily'));
// updates.push(dispatch('getBalance'));
await Promise.all(updates);
console.log('refreshing_end');

View File

@ -159,7 +159,7 @@ export function createBotSubStore(botId: string) {
[BotStoreGetters.refreshNow](state, getters, rootState, rootGetters): boolean {
const bgRefresh = rootGetters['uiSettings/backgroundSync'];
const selectedBot = rootGetters['ftbot/selectedBot'];
if ((selectedBot === botId || bgRefresh) && getters.autoRefresh) {
if ((selectedBot === botId || bgRefresh) && getters.autoRefresh && getters.isBotOnline) {
return true;
}
return false;