1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

fix: improves the loading of stats between page changes (#2985)

This commit is contained in:
Amir Raminfar
2024-05-26 10:29:26 -07:00
committed by GitHub
parent 3b34578e92
commit beb95c2f87
3 changed files with 9 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ const { containers } = defineProps<{
}>(); }>();
const totalStat = ref<Stat>({ cpu: 0, memory: 0, memoryUsage: 0 }); const totalStat = ref<Stat>({ cpu: 0, memory: 0, memoryUsage: 0 });
let history = useSimpleRefHistory(totalStat, { capacity: 300 }); const { history, reset } = useSimpleRefHistory(totalStat, { capacity: 300 });
watch( watch(
() => containers, () => containers,
@@ -37,8 +37,7 @@ watch(
); );
initial.push(stat); initial.push(stat);
} }
reset({ initial });
history = useSimpleRefHistory(totalStat, { capacity: 300, initial: initial.reverse() });
}, },
{ immediate: true }, { immediate: true },
); );
@@ -71,8 +70,4 @@ const memoryData = computed(() =>
value: formatBytes(stat.memoryUsage), value: formatBytes(stat.memoryUsage),
})), })),
); );
// watch(memoryData, () => {
// console.log(memoryData.value);
// });
</script> </script>

View File

@@ -42,7 +42,8 @@ export class Container {
public health?: ContainerHealth, public health?: ContainerHealth,
) { ) {
this._stat = ref(stats.at(-1) || ({ cpu: 0, memory: 0, memoryUsage: 0 } as Stat)); this._stat = ref(stats.at(-1) || ({ cpu: 0, memory: 0, memoryUsage: 0 } as Stat));
this._statsHistory = useSimpleRefHistory(this._stat, { capacity: 300, deep: true, initial: stats }); const { history } = useSimpleRefHistory(this._stat, { capacity: 300, deep: true, initial: stats });
this._statsHistory = history;
this.movingAverageStat = useExponentialMovingAverage(this._stat, 0.2); this.movingAverageStat = useExponentialMovingAverage(this._stat, 0.2);
this._name = name; this._name = name;

View File

@@ -73,7 +73,11 @@ export function useSimpleRefHistory<T>(source: Ref<T>, options: UseSimpleRefHist
{ deep }, { deep },
); );
return history; const reset = ({ initial = [] }: Pick<UseSimpleRefHistoryOptions<T>, "initial">) => {
history.value = initial;
};
return { history, reset };
} }
export function hashCode(str: string) { export function hashCode(str: string) {