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;
const results = await Promise.all(
tasks.map(async ({ routerId, ip, key }) => {
try {
const { data } = await api.post('/mikrotik/ping', {
serverId: routerId,
gatewayIp: ip,
target: 'www.gstatic.com',
count: 5,
});
return { key, value: typeof data?.avgMs === 'number' ? Math.round(data.avgMs) : null };
} catch (e) {
// Запросы идут параллельно; обновляем UI по мере прихода каждого ответа,
// чтобы значения на интерфейсе отображались быстрее.
tasks.forEach(({ routerId, ip, key }) => {
api
.post('/mikrotik/ping', {
serverId: routerId,
gatewayIp: ip,
target: 'www.gstatic.com',
count: 5,
})
.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);
return { key, value: null };
}
})
);
if (results.length > 0) {
setPingMap(prev => {
const next = { ...prev };
results.forEach(r => {
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) {
console.warn('prefetchPings error:', e?.message || e);
}