diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..a59ca8e9 --- /dev/null +++ b/.jules/bolt.md @@ -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] diff --git a/apps/api/src/application/who-is-working.ts b/apps/api/src/application/who-is-working.ts index b274b361..14d0f25c 100644 --- a/apps/api/src/application/who-is-working.ts +++ b/apps/api/src/application/who-is-working.ts @@ -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 {