perf: merge client status in linear time (#2703)

perf: merge client status in linear time (#2700)

Co-authored-by: potatosips <potatosips@users.noreply.github.com>
This commit is contained in:
potatosips
2026-07-21 09:38:19 +02:00
committed by GitHub
co-authored by potatosips
parent 8ae33866fc
commit 52fb584bb0
3 changed files with 86 additions and 30 deletions
+3 -30
View File
@@ -3,6 +3,7 @@ import fs from 'node:fs/promises';
import { createDebug } from 'obug';
import Database from '#server/utils/Database';
import { mergeClientStatuses } from '#server/utils/clientStatus';
import { OLD_ENV, WG_ENV } from '#server/utils/config';
import { firewall } from '#server/utils/firewall';
import { encodeQRCode } from '#server/utils/qr';
@@ -103,21 +104,7 @@ class WireGuard {
// Loop WireGuard status
const dump = await wg.dump(wgInterface.name);
dump.forEach(
({ publicKey, latestHandshakeAt, endpoint, transferRx, transferTx }) => {
const client = clients.find((client) => client.publicKey === publicKey);
if (!client) {
return;
}
client.latestHandshakeAt = latestHandshakeAt;
client.endpoint = endpoint;
client.transferRx = transferRx;
client.transferTx = transferTx;
}
);
return clients;
return mergeClientStatuses(clients, dump);
}
async dumpByPublicKey(publicKey: string) {
@@ -146,21 +133,7 @@ class WireGuard {
// Loop WireGuard status
const dump = await wg.dump(wgInterface.name);
dump.forEach(
({ publicKey, latestHandshakeAt, endpoint, transferRx, transferTx }) => {
const client = clients.find((client) => client.publicKey === publicKey);
if (!client) {
return;
}
client.latestHandshakeAt = latestHandshakeAt;
client.endpoint = endpoint;
client.transferRx = transferRx;
client.transferTx = transferTx;
}
);
return clients;
return mergeClientStatuses(clients, dump);
}
async getClientConfiguration({ clientId }: { clientId: ID }) {