Skip to content

Commit e8a02a7

Browse files
committed
Make isRestoreInProgress computed
1 parent 25427fd commit e8a02a7

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/Frontend/src/components/failedmessages/DeletedMessageGroups.vue

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, watch } from "vue";
2+
import { ref, computed, watch } from "vue";
33
import { useRouter } from "vue-router";
44
import { useShowToast } from "../../composables/toast";
55
import NoData from "../NoData.vue";
@@ -18,8 +18,10 @@ import { useStoreAutoRefresh } from "@/composables/useAutoRefresh";
1818
import { storeToRefs } from "pinia";
1919
import LoadingSpinner from "../LoadingSpinner.vue";
2020
21-
let pollingFaster = false;
22-
const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh("deletedMessageGroups", useDeletedMessageGroupsStore, 5000);
21+
const POLLING_INTERVAL_NORMAL = 5000;
22+
const POLLING_INTERVAL_FAST = 1000;
23+
24+
const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh("deletedMessageGroups", useDeletedMessageGroupsStore, POLLING_INTERVAL_NORMAL);
2325
const { store } = autoRefresh();
2426
const { archiveGroups, classifiers, selectedClassifier } = storeToRefs(store);
2527
const router = useRouter();
@@ -47,8 +49,7 @@ async function restoreGroup() {
4749
useShowToast(TYPE.ERROR, "Error", `Failed to restore the group: ${errorMessage}`);
4850
} else {
4951
// We're starting a restore, poll more frequently
50-
pollingFaster = true;
51-
updateInterval(1000);
52+
updateInterval(POLLING_INTERVAL_FAST);
5253
useShowToast(TYPE.INFO, "Info", "Group restore started...");
5354
}
5455
}
@@ -79,19 +80,17 @@ function navigateToGroup(groupId: string) {
7980
router.push(routeLinks.failedMessage.deletedGroup.link(groupId));
8081
}
8182
82-
function isRestoreInProgress() {
83+
const isRestoreInProgress = computed(() => {
8384
return archiveGroups.value.some((group) => group.workflow_state.status !== "none" && group.workflow_state.status !== "restorecompleted");
84-
}
85+
});
8586
86-
watch(isRefreshing, () => {
87-
// If we're currently polling at 5 seconds and there is a restore in progress, then change the polling interval to poll every 1 second
88-
if (!pollingFaster && isRestoreInProgress()) {
89-
pollingFaster = true;
90-
updateInterval(1000);
91-
} else if (pollingFaster && !isRestoreInProgress()) {
92-
// if we're currently polling every 1 second and all restores are done, change polling frequency back to every 5 seconds
93-
pollingFaster = false;
94-
updateInterval(5000);
87+
watch(isRestoreInProgress, (restoreInProgress) => {
88+
if (restoreInProgress) {
89+
// If there is a restore in progress, poll every 1 second
90+
updateInterval(POLLING_INTERVAL_FAST);
91+
} else {
92+
// If all restores are done, change polling frequency back to every 5 seconds
93+
updateInterval(POLLING_INTERVAL_NORMAL);
9594
}
9695
});
9796
</script>

0 commit comments

Comments
 (0)