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

This commit is contained in:
2026-02-22 01:30:21 +07:00
parent f0cb694fa6
commit afa093781e
2 changed files with 22 additions and 10 deletions
+3 -1
View File
@@ -396,10 +396,12 @@ function initNetworkMapScheduler(logger, port) {
const intervalMs = settings.intervalMinutes * 60 * 1000; const intervalMs = settings.intervalMinutes * 60 * 1000;
log.info( log.info(
{ component: 'network-map-scheduler', intervalMinutes: settings.intervalMinutes }, { 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 settings.intervalMinutes
); );
schedulerTimer = setInterval(tick, intervalMs); schedulerTimer = setInterval(tick, intervalMs);
// Первый запуск через 10 сек, чтобы кеш появился вскоре после старта сервера
setTimeout(() => tick(), 10 * 1000);
} }
schedule(); schedule();
+19 -9
View File
@@ -139,16 +139,18 @@ export default function NetworkMapDashboard() {
setConnections(connList); setConnections(connList);
const cacheMaxAgeMs = Math.max((ttlSeconds || 60) * 1000, 60 * 1000); 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 = const cacheValid =
cache.updatedAt && cache.updatedAt &&
Date.now() - cache.updatedAt < cacheMaxAgeMs && Date.now() - cache.updatedAt < cacheMaxAgeMs &&
(Object.keys(cache.pingMap || {}).length > 0 || Object.keys(cache.speedMap || {}).length > 0); hasCacheData;
if (cacheValid) {
const cachedPingMap = cache.pingMap || {}; if (hasCacheData) {
const cachedSpeedMap = cache.speedMap || {}; // Всегда показываем кеш, если он есть — чтобы на карте отображались хотя бы прошлые пинг/скорость
setPingMap(cachedPingMap); setPingMap(cachedPingMap);
setSpeedMap(cachedSpeedMap); setSpeedMap(cachedSpeedMap);
// Сохраняем успешные значения из кеша
Object.keys(cachedPingMap).forEach((k) => { Object.keys(cachedPingMap).forEach((k) => {
if (typeof cachedPingMap[k] === 'number') { if (typeof cachedPingMap[k] === 'number') {
lastSuccessfulPingRef.current[k] = cachedPingMap[k]; lastSuccessfulPingRef.current[k] = cachedPingMap[k];
@@ -161,12 +163,20 @@ export default function NetworkMapDashboard() {
} }
}); });
cacheAppliedAtRef.current = cache.updatedAt; cacheAppliedAtRef.current = cache.updatedAt;
// Сбрасываем флаги устаревших данных при загрузке валидного кеша // Устаревший кеш (старше TTL) помечаем как stale, но данные всё равно отображаем
setPingStaleMap({}); if (cacheValid) {
setSpeedStaleMap({}); 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 { } else {
setSpeedMap({}); setSpeedMap({});
// При невалидном кеше также сбрасываем флаги
setPingStaleMap({}); setPingStaleMap({});
setSpeedStaleMap({}); setSpeedStaleMap({});
} }