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

View File

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

View File

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