Skip to content

Commit

Permalink
add stat clear timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed May 29, 2024
1 parent 3dd8d8b commit cb1ff77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
1 change: 0 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func (cr *Cluster) apiV0Stat(rw http.ResponseWriter, req *http.Request) {
writeJson(rw, http.StatusOK, &cr.stats)
return
}
print("name:", name)
data, err := cr.stats.MarshalSubStat(name)
if err != nil {
http.Error(rw, "Error when encoding response: "+err.Error(), http.StatusInternalServerError)
Expand Down
30 changes: 21 additions & 9 deletions dashboard/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getStat,
getPprofURL,
EMPTY_STAT,
type Stats,
type StatusRes,
type PprofLookups,
} from '@/api/v0'
Expand Down Expand Up @@ -75,23 +76,34 @@ const avaliableStorages = computed(() => {
})
const activeStorageIndex = ref(0)
const activeStats = computedAsync(async () => {
if (!data.value) {
return null
const activeStats = ref<Stats | null>(null)
watch([data, activeStorageIndex], async ([data, newIndex]) => {
if (!data) {
activeStats.value = null
return
}
if (!activeStorageIndex.value) {
return data.value.stats
if (!newIndex) {
activeStats.value = data.stats
return
}
const storageId = data.value.storages[activeStorageIndex.value - 1]
const storageId = data.storages[newIndex - 1]
if (!storageId) {
activeStorageIndex.value = 0
return null
activeStats.value = null
return
}
const clearTimerId = setTimeout(() => {
activeStats.value = null
}, 300)
const res = await getStat(storageId, token.value)
clearTimeout(clearTimerId)
if (res === null) {
return JSON.parse(JSON.stringify(EMPTY_STAT))
activeStats.value = JSON.parse(JSON.stringify(EMPTY_STAT))
return
}
return res
activeStats.value = res
return
})
async function requestPprof(lookup: PprofLookups, view?: boolean): Promise<void> {
Expand Down

0 comments on commit cb1ff77

Please sign in to comment.