From ca8d4bb5cfa3c87927d1bb02c148e7812d96699d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 27 Jun 2026 08:43:06 +0000 Subject: [PATCH] perf: derive project lists in-memory to prevent waterfall - Removes redundant fetch to `/api/projects/[id]/lists`. - Derives the project's lists using an in-memory array `.filter()` against the global `allLists` result. - Avoids duplicate database scans when both all lists and project lists are required simultaneously. Co-authored-by: aicoder2009 <127642633+aicoder2009@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ src/app/projects/[id]/page.tsx | 17 +++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 43fafef..401194b 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -5,3 +5,7 @@ ## 2024-05-18 - Concurrent Fetching with Owner IDs in Share Links **Learning:** In the share system, endpoints processing a share code typically suffer from waterfall latency by first loading target entity details (like a project) and then querying its associated elements (like project lists) using the entity's owner ID (`userId`). However, the `shareLink` object already contains the `userId` field (representing the owner's ID). **Action:** Always leverage the existing owner's ID within `shareLink` to bypass sequential dependencies and fetch parent entities (like projects) concurrently with their child elements (like user lists) using `Promise.all`. + +## 2025-02-12 - Derive Subsets In-Memory +**Learning:** The DynamoDB implementation lacks a Global Secondary Index (GSI) for `projectId` on lists, so backend endpoints (like `/api/projects/[id]/lists`) fetch all of a user's lists and filter them in memory anyway. +**Action:** When a global collection (like all lists) and a subset of that collection (like project lists) are needed simultaneously on the frontend, fetch the global collection and derive the subset in-memory using array filtering. This prevents redundant backend database queries and eliminates an unnecessary API request, improving page load performance. diff --git a/src/app/projects/[id]/page.tsx b/src/app/projects/[id]/page.tsx index 8e121a4..dd635a6 100644 --- a/src/app/projects/[id]/page.tsx +++ b/src/app/projects/[id]/page.tsx @@ -58,17 +58,15 @@ export default function ProjectDetailPage({ params }: { params: Promise<{ id: st setIsLoading(true); // OPTIMIZATION: Execute independent network requests and JSON parsing concurrently - // using Promise.all. This prevents a 3-step waterfall, reducing Time to First Byte - // (TTFB) and overall load time significantly on this detail page. - const [projectRes, listsRes, allListsRes] = await Promise.all([ + // using Promise.all. This prevents a waterfall, reducing Time to First Byte (TTFB). + // We fetch all lists and derive the project's lists in-memory to avoid a redundant API call. + const [projectRes, allListsRes] = await Promise.all([ fetch(`/api/projects/${projectId}`), - fetch(`/api/projects/${projectId}/lists`), fetch("/api/lists"), ]); - const [projectResult, listsResult, allListsResult] = await Promise.all([ + const [projectResult, allListsResult] = await Promise.all([ projectRes.json(), - listsRes.json(), allListsRes.json(), ]); @@ -81,12 +79,11 @@ export default function ProjectDetailPage({ params }: { params: Promise<{ id: st setEditName(projectResult.data.name); setEditDescription(projectResult.data.description || ""); - if (listsResult.success) { - setLists(listsResult.data); - } - if (allListsResult.success) { setAllLists(allListsResult.data); + // OPTIMIZATION: Derive project-specific lists in-memory from allLists + // instead of making a duplicate backend database query. + setLists(allListsResult.data.filter((list: List) => list.projectId === projectId)); } } catch (err) { console.error("Error fetching project:", err);