From ff9c318a9b6bfd6d0b2ddf51e6976fe96299b20c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:04:10 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20array=20lookups?= =?UTF-8?q?=20with=20Map=20in=20Territory=20Workspace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: brycejohnson1417 <257422776+brycejohnson1417@users.noreply.github.com> --- .jules/bolt.md | 0 components/territory/territory-workspace.tsx | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..e69de29 diff --git a/components/territory/territory-workspace.tsx b/components/territory/territory-workspace.tsx index 6d2ff49..7873f9c 100644 --- a/components/territory/territory-workspace.tsx +++ b/components/territory/territory-workspace.tsx @@ -570,13 +570,24 @@ export function TerritoryWorkspace({ orgSlug, initialDashboard, territoryConfig const mobileViewAutoSwitchedRef = useRef(initialPreferListView); const pins = data.pins; - const selectedPin = useMemo(() => pins.find((pin) => pin.id === selectedId) ?? null, [pins, selectedId]); + + // ⚡ Bolt: Optimize pin lookups by creating a dictionary (O(1) lookups instead of O(N) array finds) + const pinsById = useMemo(() => { + return new Map(pins.map((pin) => [pin.id, pin])); + }, [pins]); + + const selectedPin = useMemo(() => { + if (!selectedId) return null; + const pin = pinsById.get(selectedId); + return pin ?? null; + }, [pinsById, selectedId]); + const routeStops = useMemo( () => routePlanningEnabled - ? routeStopIds.map((id) => pins.find((pin) => pin.id === id)).filter((pin): pin is TerritoryAccountPin => Boolean(pin)) + ? routeStopIds.map((id) => pinsById.get(id)).filter((pin): pin is TerritoryAccountPin => Boolean(pin)) : [], - [pins, routePlanningEnabled, routeStopIds], + [pinsById, routePlanningEnabled, routeStopIds], ); const mappablePinCount = useMemo(() => pins.filter(hasUsableCoordinates).length, [pins]); const activeFilterCount = Object.values(filters).filter(Boolean).length;