Skip to content

Commit b644dc8

Browse files
committed
perf(discovery): cache pool discovery results to avoid repeated remote stalls
1 parent 5f70191 commit b644dc8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

apps/dashboard/server.mjs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9317,6 +9317,12 @@ function startBscYieldWorker(options = {}) {
93179317
}, BSC_YIELD_WORKER.intervalMs);
93189318
}
93199319

9320+
const BSC_POOL_DISCOVERY_CACHE = {
9321+
lista: { ts: 0, value: null },
9322+
wombat: { ts: 0, value: null },
9323+
};
9324+
const BSC_POOL_DISCOVERY_CACHE_TTL_MS = 60_000;
9325+
93209326
function parseAddressCandidates(raw) {
93219327
return String(raw || "")
93229328
.split(/[\n,;\s]+/)
@@ -9595,6 +9601,13 @@ async function scorePoolCandidates(candidates, protocol) {
95959601

95969602
async function discoverBscPoolsByProtocol(protocol) {
95979603
const key = String(protocol || "").toLowerCase();
9604+
const cache = BSC_POOL_DISCOVERY_CACHE[key];
9605+
if (
9606+
cache?.value &&
9607+
Date.now() - Number(cache.ts || 0) < BSC_POOL_DISCOVERY_CACHE_TTL_MS
9608+
) {
9609+
return cache.value;
9610+
}
95989611
const candidateRaw =
95999612
key === "lista" ? BSC_LISTA_POOL_CANDIDATES : BSC_WOMBAT_POOL_CANDIDATES;
96009613
let candidates = parseAddressCandidates(candidateRaw);
@@ -9651,7 +9664,7 @@ async function discoverBscPoolsByProtocol(protocol) {
96519664
: recommended
96529665
? "low"
96539666
: "none";
9654-
return {
9667+
const result = {
96559668
protocol: key,
96569669
source,
96579670
reasonCode,
@@ -9660,6 +9673,11 @@ async function discoverBscPoolsByProtocol(protocol) {
96609673
recommended,
96619674
warning,
96629675
};
9676+
if (cache) {
9677+
cache.ts = Date.now();
9678+
cache.value = result;
9679+
}
9680+
return result;
96639681
}
96649682

96659683
function parseDotEnv(raw) {

0 commit comments

Comments
 (0)