From b34c1acbca624025470e837ff160c473bb017410 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2026 19:30:55 +0000 Subject: [PATCH] Optimize seed lookup from O(N) to O(1) in mock.js Created a `SEED_MAP` to index the SEEDS array by device_id. This replaces the linear `SEEDS.find(...)` lookup inside the `seed(id)` function with a constant-time `SEED_MAP.get(id)`, significantly reducing lookup latency for repeated calls. Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com> --- v2/crates/homecore-server/ui/js/mock.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v2/crates/homecore-server/ui/js/mock.js b/v2/crates/homecore-server/ui/js/mock.js index cb1add5b63..0797ae3c2c 100644 --- a/v2/crates/homecore-server/ui/js/mock.js +++ b/v2/crates/homecore-server/ui/js/mock.js @@ -124,8 +124,11 @@ const SEEDS = [ warnings: ['stale firmware version (0.6.9 < 0.7.3)', 'offline > 1h'], }, ]; + +const SEED_MAP = new Map(SEEDS.map((s) => [s.device_id, s])); + export function seeds() { return SEEDS.map((s) => ({ ...s })); } -export function seed(id) { return SEEDS.find((s) => s.device_id === id) || null; } +export function seed(id) { return SEED_MAP.get(id) || null; } // ── ESP32 node warnings (§4.1) ────────────────────────────────────── export function esp32Warnings() {