Skip to content

Commit a4c082d

Browse files
committed
Update.
1 parent df751bf commit a4c082d

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

cmd/dashboard/controller/common_page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ func (cp *commonPage) ws(c *gin.Context) {
10341034
defer cancel()
10351035

10361036
count := 0
1037-
ticker := time.NewTicker(time.Second)
1037+
ticker := time.NewTicker(2 * time.Second) // 从1秒改为2秒,减少推送频率
10381038
defer ticker.Stop()
10391039

10401040
// 使用ticker而非sleep循环,减少goroutine占用

resource/template/theme-default/home.html

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,10 @@
416416
});
417417
}
418418

419-
// 设置定期更新
419+
// 设置定期更新,降低频率减少跳动
420420
this._updateInterval = setInterval(() => {
421421
this.updateServerLiveStatus({ now: Date.now() });
422-
}, 1000); // 改回1秒更新一次
422+
}, 3000); // 改为3秒更新一次,减少频繁跳动
423423
},
424424
mounted() {
425425
this.$nextTick(() => {
@@ -551,7 +551,8 @@
551551
let displayPercentValue = percent;
552552
let classObject = { ui: true, progress: true };
553553
let styleObject = {
554-
'transition-duration': '300ms',
554+
'transition-duration': '800ms', // 增加过渡时间,使变化更平滑
555+
'transition-timing-function': 'ease-out',
555556
'min-width': 'unset',
556557
width: (percent >= 0 ? percent : 0) + '% !important',
557558
};
@@ -763,21 +764,43 @@
763764
}
764765
}
765766

766-
// 计算在线状态
767+
// 计算在线状态 - 增加稳定性,减少频繁跳动
767768
const lastActiveTimestampMs = new Date(serverItem.LastActive).getTime();
768769
const diffMs = nowMillisFromWS - lastActiveTimestampMs;
769-
const newLiveStatus = !isNaN(lastActiveTimestampMs) && diffMs <= 30000 && diffMs >= -5000;
770-
771-
// 只有在状态发生变化时才更新
770+
771+
// 增加容错时间,减少误判:60秒超时 + 10秒容错
772+
const newLiveStatus = !isNaN(lastActiveTimestampMs) && diffMs <= 60000 && diffMs >= -10000;
773+
774+
// 添加状态稳定性检查,避免频繁切换
772775
if (serverItem.live !== newLiveStatus) {
776+
// 如果状态要从在线变为离线,需要连续2次确认
777+
if (serverItem.live === true && newLiveStatus === false) {
778+
if (!serverItem._offlineConfirmCount) {
779+
serverItem._offlineConfirmCount = 1;
780+
return; // 第一次检测到离线,不立即更新
781+
} else {
782+
serverItem._offlineConfirmCount = 0; // 重置计数器
783+
}
784+
} else if (serverItem.live === false && newLiveStatus === true) {
785+
// 从离线恢复到在线,立即更新
786+
serverItem._offlineConfirmCount = 0;
787+
}
788+
773789
serverItem.live = newLiveStatus;
774790
hasUpdates = true;
775791
}
776792
});
777793

778-
// 只有在有实际更新时才强制更新视图
794+
// 只有在有实际更新时才强制更新视图,并添加防抖
779795
if (hasUpdates) {
780-
this.$forceUpdate();
796+
// 使用防抖机制,避免频繁更新
797+
if (this._updateDebounceTimer) {
798+
clearTimeout(this._updateDebounceTimer);
799+
}
800+
this._updateDebounceTimer = setTimeout(() => {
801+
this.$forceUpdate();
802+
this._updateDebounceTimer = null;
803+
}, 500); // 500ms 防抖
781804
}
782805
},
783806
getTrafficProgressClass(serverId) {
@@ -956,6 +979,9 @@
956979
if (this._updateInterval) {
957980
clearInterval(this._updateInterval);
958981
}
982+
if (this._updateDebounceTimer) {
983+
clearTimeout(this._updateDebounceTimer);
984+
}
959985
if (window.trafficManager) {
960986
window.trafficManager.unsubscribe(this.updateTrafficData);
961987
}

service/singleton/singleton.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ func CheckServerOnlineStatus() {
879879
defer ServerLock.Unlock()
880880

881881
now := time.Now()
882-
offlineTimeout := time.Minute * 3 // 增加到3分钟无心跳视为离线,减少误报
882+
offlineTimeout := time.Minute * 2 // 调整为2分钟无心跳视为离线,平衡稳定性和响应速度
883883

884884
// 检查是否需要重置累计流量数据
885885
shouldResetTransferStats := checkShouldResetTransferStats()

0 commit comments

Comments
 (0)