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
+17 -29
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
serverId: routerId, .post('/mikrotik/ping', {
gatewayIp: ip, serverId: routerId,
target: 'www.gstatic.com', gatewayIp: ip,
count: 5, target: 'www.gstatic.com',
}); count: 5,
return { key, value: typeof data?.avgMs === 'number' ? Math.round(data.avgMs) : null }; })
} catch (e) { .then(({ data }) => {
const value = typeof data?.avgMs === 'number' ? Math.round(data.avgMs) : null;
setPingMap((prev) => ({ ...prev, [key]: value }));
})
.catch((e) => {
console.warn('Failed to fetch ping for', routerId, ip, e?.message || e); console.warn('Failed to fetch ping for', routerId, ip, e?.message || e);
return { key, value: null }; setPingMap((prev) => ({ ...prev, [key]: null }));
}
})
);
if (results.length > 0) {
setPingMap(prev => {
const next = { ...prev };
results.forEach(r => {
next[r.key] = r.value;
}); });
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);
} }