Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-18 - Concurrent Fetching in API Routes
**Learning:** In Next.js App Router API routes, multiple independent database fetches (like getting user shares, lists, and projects) often happen sequentially when using simple `await` statements one after the other. This creates unnecessary latency. Grouping them into `await Promise.all([])` executes them concurrently.
**Action:** Always scan API routes and server components for sequential `await` calls that do not depend on each other's results, and refactor them to use `Promise.all` to reduce overall execution time.
9 changes: 6 additions & 3 deletions src/app/api/share/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export async function GET() {
);
}

const shares = await listUserShares(userId);
// Fetch data concurrently to minimize latency
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]));

Expand Down
Loading