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 @@
## 2025-02-12 - [Parallelize DB queries in use cases]
**Learning:** [When compiling complex use-case models with active locks, sessions, and PRs, sequentially `await`ing individual stores blocks unnecessarily]
**Action:** [Bundle independent Prisma/Store queries using `Promise.all` wherever aggregation endpoints merge multiple data domains]
18 changes: 13 additions & 5 deletions apps/api/src/application/who-is-working.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ export async function whoIsWorking(
return { status: "FORBIDDEN" };
}

const sessions = (await activeSessions(deps.workSessionStore, found.usecase.id)).map(
(session) => sessionRow(deps, session)
);
const locks = (await activeLocks(deps, found.usecase.id)).map(lockRow);
const mergeRequests = (await openMergeRequests(deps, found.usecase.id)).map(mergeRow);
// ⚡ Bolt Optimization:
// 💡 What: Replaced sequential `await` calls with `Promise.all` for parallel execution.
// 🎯 Why: `activeSessions`, `activeLocks`, and `openMergeRequests` are independent network/database calls. Running them sequentially caused unnecessary blocking.
// 📊 Impact: Reduces query time from (T1 + T2 + T3) to max(T1, T2, T3). Speeds up `whoIsWorking` endpoint noticeably, especially on high latency connections or larger databases.
const [rawSessions, rawLocks, rawMergeRequests] = await Promise.all([
activeSessions(deps.workSessionStore, found.usecase.id),
activeLocks(deps, found.usecase.id),
openMergeRequests(deps, found.usecase.id)
]);

const sessions = rawSessions.map((session) => sessionRow(deps, session));
const locks = rawLocks.map(lockRow);
const mergeRequests = rawMergeRequests.map(mergeRow);
const hasActiveWork = sessions.length + locks.length + mergeRequests.length > 0;

return {
Expand Down