feat(NetworkMap): adjust network map scheduler to run initial tick after 10 seconds and enhance cache handling in dashboard for better data display
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m54s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m54s
This commit is contained in:
@@ -396,10 +396,12 @@ function initNetworkMapScheduler(logger, port) {
|
||||
const intervalMs = settings.intervalMinutes * 60 * 1000;
|
||||
log.info(
|
||||
{ component: 'network-map-scheduler', intervalMinutes: settings.intervalMinutes },
|
||||
'Network map scheduler started (first run in %d min)',
|
||||
'Network map scheduler started (first run in 10 s, then every %d min)',
|
||||
settings.intervalMinutes
|
||||
);
|
||||
schedulerTimer = setInterval(tick, intervalMs);
|
||||
// Первый запуск через 10 сек, чтобы кеш появился вскоре после старта сервера
|
||||
setTimeout(() => tick(), 10 * 1000);
|
||||
}
|
||||
|
||||
schedule();
|
||||
|
||||
@@ -139,16 +139,18 @@ export default function NetworkMapDashboard() {
|
||||
setConnections(connList);
|
||||
|
||||
const cacheMaxAgeMs = Math.max((ttlSeconds || 60) * 1000, 60 * 1000);
|
||||
const cachedPingMap = cache.pingMap && typeof cache.pingMap === 'object' ? cache.pingMap : {};
|
||||
const cachedSpeedMap = cache.speedMap && typeof cache.speedMap === 'object' ? cache.speedMap : {};
|
||||
const hasCacheData = Object.keys(cachedPingMap).length > 0 || Object.keys(cachedSpeedMap).length > 0;
|
||||
const cacheValid =
|
||||
cache.updatedAt &&
|
||||
Date.now() - cache.updatedAt < cacheMaxAgeMs &&
|
||||
(Object.keys(cache.pingMap || {}).length > 0 || Object.keys(cache.speedMap || {}).length > 0);
|
||||
if (cacheValid) {
|
||||
const cachedPingMap = cache.pingMap || {};
|
||||
const cachedSpeedMap = cache.speedMap || {};
|
||||
hasCacheData;
|
||||
|
||||
if (hasCacheData) {
|
||||
// Всегда показываем кеш, если он есть — чтобы на карте отображались хотя бы прошлые пинг/скорость
|
||||
setPingMap(cachedPingMap);
|
||||
setSpeedMap(cachedSpeedMap);
|
||||
// Сохраняем успешные значения из кеша
|
||||
Object.keys(cachedPingMap).forEach((k) => {
|
||||
if (typeof cachedPingMap[k] === 'number') {
|
||||
lastSuccessfulPingRef.current[k] = cachedPingMap[k];
|
||||
@@ -161,12 +163,20 @@ export default function NetworkMapDashboard() {
|
||||
}
|
||||
});
|
||||
cacheAppliedAtRef.current = cache.updatedAt;
|
||||
// Сбрасываем флаги устаревших данных при загрузке валидного кеша
|
||||
setPingStaleMap({});
|
||||
setSpeedStaleMap({});
|
||||
// Устаревший кеш (старше TTL) помечаем как stale, но данные всё равно отображаем
|
||||
if (cacheValid) {
|
||||
setPingStaleMap({});
|
||||
setSpeedStaleMap({});
|
||||
} else {
|
||||
const stalePing = {};
|
||||
const staleSpeed = {};
|
||||
Object.keys(cachedPingMap).forEach((k) => { stalePing[k] = true; });
|
||||
Object.keys(cachedSpeedMap).forEach((k) => { staleSpeed[k] = true; });
|
||||
setPingStaleMap(stalePing);
|
||||
setSpeedStaleMap(staleSpeed);
|
||||
}
|
||||
} else {
|
||||
setSpeedMap({});
|
||||
// При невалидном кеше также сбрасываем флаги
|
||||
setPingStaleMap({});
|
||||
setSpeedStaleMap({});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user