refactor(EasySwitchManager): optimize ping requests by using parallel execution and immediate UI updates for improved responsiveness
Publish Fast Tabler Docker image / build-and-push-fast (push) Failing after 3m42s

This commit is contained in:
2026-02-11 00:22:13 +07:00
parent a0bf4a7a9f
commit 343626c350
+12 -24
View File
@@ -284,37 +284,25 @@ function EasySwitchManager() {
if (tasks.length === 0) return; if (tasks.length === 0) return;
const results = await Promise.all( // Запросы идут параллельно; обновляем UI по мере прихода каждого ответа,
tasks.map(async ({ routerId, ip, key }) => { // чтобы значения на интерфейсе отображались быстрее.
try { tasks.forEach(({ routerId, ip, key }) => {
const { data } = await api.post('/mikrotik/ping', { api
.post('/mikrotik/ping', {
serverId: routerId, serverId: routerId,
gatewayIp: ip, gatewayIp: ip,
target: 'www.gstatic.com', target: 'www.gstatic.com',
count: 5, count: 5,
});
return { key, value: typeof data?.avgMs === 'number' ? Math.round(data.avgMs) : null };
} catch (e) {
console.warn('Failed to fetch ping for', routerId, ip, e?.message || e);
return { key, value: null };
}
}) })
); .then(({ data }) => {
const value = typeof data?.avgMs === 'number' ? Math.round(data.avgMs) : null;
if (results.length > 0) { setPingMap((prev) => ({ ...prev, [key]: value }));
setPingMap(prev => { })
const next = { ...prev }; .catch((e) => {
results.forEach(r => { console.warn('Failed to fetch ping for', routerId, ip, e?.message || e);
next[r.key] = r.value; setPingMap((prev) => ({ ...prev, [key]: null }));
}); });
return next;
}); });
try {
console.log('[EasySwitch] ping tasks count:', tasks.length);
console.log('[EasySwitch] ping results sample:', results.slice(0, 10));
} catch (_) {}
}
} catch (e) { } catch (e) {
console.warn('prefetchPings error:', e?.message || e); console.warn('prefetchPings error:', e?.message || e);
} }