From 6245265d79bfc5012496a71a97b1c969f2c5a16a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 27 Mar 2026 20:51:51 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Optimize=20array=20lookups=20with=20Sets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Converted O(N*M) array `includes` lookups into O(N+M) `Set.has()` operations inside the `proposals/voters/add` and `proposals/voters/remove` endpoints. This significantly improves the efficiency of filtering domain owners against existing voters when processing adding or removing voters for the TLD Migration Proposal. Co-authored-by: yeboster <23556525+yeboster@users.noreply.github.com> --- src/routes/api/proposals/voters/add/+server.ts | 5 ++++- src/routes/api/proposals/voters/remove/+server.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/routes/api/proposals/voters/add/+server.ts b/src/routes/api/proposals/voters/add/+server.ts index 62f2caf8..3809495b 100644 --- a/src/routes/api/proposals/voters/add/+server.ts +++ b/src/routes/api/proposals/voters/add/+server.ts @@ -23,7 +23,10 @@ export async function GET() { ?.setValue() .values.map((voter) => voter.addressValue().value.toString('hex')) ?? []; - const newVoters = owners.filter((owner) => !voters.includes(owner)).slice(0, 50); + // ⚡ Bolt: Convert voters array to a Set for O(1) lookups instead of O(N) Array.includes + // This changes the filter operation from O(N * M) to O(N + M) complexity + const votersSet = new Set(voters); + const newVoters = owners.filter((owner) => !votersSet.has(owner)).slice(0, 50); if (newVoters.length === 0) return json({ newVoters }, { status: 200 }); const votingContract = await metaNamesSdk.contractRepository.getContract({ diff --git a/src/routes/api/proposals/voters/remove/+server.ts b/src/routes/api/proposals/voters/remove/+server.ts index d024e90f..1a431c75 100644 --- a/src/routes/api/proposals/voters/remove/+server.ts +++ b/src/routes/api/proposals/voters/remove/+server.ts @@ -25,7 +25,10 @@ export async function GET() { ?.setValue() .values.map((voter) => voter.addressValue().value.toString('hex')) ?? []; - const votersToRemove = voters.filter((voter) => !owners.includes(voter)).slice(0, 50); + // ⚡ Bolt: Convert owners array to a Set for O(1) lookups instead of O(N) Array.includes + // This changes the filter operation from O(N * M) to O(N + M) complexity + const ownersSet = new Set(owners); + const votersToRemove = voters.filter((voter) => !ownersSet.has(voter)).slice(0, 50); if (votersToRemove.length === 0) return json({ newVoters: votersToRemove }, { status: 200 }); const votingContract = await metaNamesSdk.contractRepository.getContract({