diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..4548daf --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-05-01 - Concurrent Fetching in Share API +**Learning:** Sequential database queries (like `listUserShares` followed by `getUserLists` and `getUserProjects`) create unnecessary waterfall latency, especially for independent datasets. +**Action:** Always group independent async database calls using `Promise.all` to reduce total latency, as done in `GET /api/share`. diff --git a/src/app/api/share/route.ts b/src/app/api/share/route.ts index 618a120..a9294c2 100644 --- a/src/app/api/share/route.ts +++ b/src/app/api/share/route.ts @@ -22,11 +22,15 @@ export async function GET() { ); } - const shares = await listUserShares(userId); + // Fetch shares, lists, and projects concurrently to minimize database latency + // and resolve the waterfall fetching pattern. + const [shares, lists, projects] = await Promise.all([ + listUserShares(userId), + getUserLists(userId), + getUserProjects(userId), + ]); // Enrich with target name so the UI can render without extra round-trips. - const lists = await getUserLists(userId); - const projects = await getUserProjects(userId); const listById = new Map(lists.map((l) => [l.id, l])); const projectById = new Map(projects.map((p) => [p.id, p]));