Skip to content

⚡ Bolt: Optimize usage records aggregation to single pass#37

Closed
seonghobae wants to merge 1 commit into
mainfrom
bolt-optimize-usage-records-aggregation-16663085473334058751
Closed

⚡ Bolt: Optimize usage records aggregation to single pass#37
seonghobae wants to merge 1 commit into
mainfrom
bolt-optimize-usage-records-aggregation-16663085473334058751

Conversation

@seonghobae

Copy link
Copy Markdown

💡 What: Replaced multiple .reduce() iterations over session.usageRecords with a single for...of loop in the packages/web/src/app/api/orgs/[orgSlug]/dashboard/sessions/ API routes.
🎯 Why: To improve backend performance by reducing iteration overhead and potential memory bottlenecks when aggregating session totals (input tokens, output tokens, cost) from potentially large usage record arrays.
📊 Impact: Reduces the time complexity of the aggregation from O(3N) to O(N), improving response times for session dashboard APIs.
🔬 Measurement: Code review verified the theoretical performance win. E2E tests, API tests, and Next.js builds have verified that the functionality remains identical.


PR created automatically by Jules for task 16663085473334058751 started by @seonghobae

Combined three separate `.reduce()` calls into a single `for...of` loop
when aggregating `inputTokens`, `outputTokens`, and `estimatedCostUsd`
over `session.usageRecords`. This reduces the iteration time complexity
from O(3N) to O(N), which minimizes iteration overhead and memory bottlenecks
for large datasets returned from Prisma include blocks.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

워크스루

세션 대시보드 API의 두 라우트에서 사용 기록 합산 로직을 최적화했습니다. 기존의 3회 reduce 호출을 단일 for...of 루프로 통합하여 배열 순회 횟수를 감소시켰습니다.

변경사항

토큰 및 비용 집계 최적화

Layer / File(s) 요약
토큰 및 비용 계산 통합
packages/web/src/app/api/orgs/[orgSlug]/dashboard/sessions/[sessionId]/route.ts, packages/web/src/app/api/orgs/[orgSlug]/dashboard/sessions/route.ts
두 라우트에서 usageRecords의 입력/출력 토큰과 추정 비용을 합산하던 3회 reduce 호출을 단일 for...of 루프로 통합했습니다. 루프 내에서 totalInput, totalOutput, totalCost를 동시에 누적하도록 변경되었으며, undefined 비용값은 기존과 동일하게 0으로 처리됩니다.

예상 검토 난이도

🎯 2 (간단함) | ⏱️ ~8분

시인의 축하 시

🐰 세 번 도는 바퀴를 하나로 깎아
루프 하나가 주욱 흐르네요
배열은 한 번, 비용은 한 번
토큰도 한 번에 쌓여 가고
최적화의 길은 아름답고
순회는 빨라지는 마법이지요! ✨


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Docstring Coverage ❌ Error Docstring coverage is 50.00% which is insufficient. The required threshold is 100.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 주요 변경사항을 명확하게 요약합니다: 사용 레코드 집계를 단일 패스로 최적화했다는 내용이 정확히 반영되어 있습니다.
Description check ✅ Passed PR 설명이 변경사항과 관련이 있으며, What/Why/Impact를 명확히 설명하고 성능 최적화(O(3N)→O(N))와 검증 과정을 구체적으로 기술합니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-optimize-usage-records-aggregation-16663085473334058751
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch bolt-optimize-usage-records-aggregation-16663085473334058751

Comment @coderabbitai help to get the list of available commands and usage tips.

@seonghobae

Copy link
Copy Markdown
Author

최신 upstream/main 기준으로 이 PR은 81개 파일의 stale diff를 포함합니다. 특히 .claude agent/skill 파일 삭제와 오래된 워크플로우/lockfile/env 변경이 섞여 있어 그대로 유지하거나 upstream에 올리면 이미 반영된 변경을 되돌릴 위험이 큽니다.

현재 큐는 upstream #30 → upstream #21 순서로 정리 중입니다. 이 PR의 아이디어가 여전히 필요하면 최신 upstream/main에서 단일 목적 브랜치로 깨끗하게 다시 추출하겠습니다. stale PR로 닫습니다.

@seonghobae seonghobae closed this Jun 10, 2026
@google-labs-jules

Copy link
Copy Markdown

최신 upstream/main 기준으로 이 PR은 81개 파일의 stale diff를 포함합니다. 특히 .claude agent/skill 파일 삭제와 오래된 워크플로우/lockfile/env 변경이 섞여 있어 그대로 유지하거나 upstream에 올리면 이미 반영된 변경을 되돌릴 위험이 큽니다.

현재 큐는 upstream #30 → upstream #21 순서로 정리 중입니다. 이 PR의 아이디어가 여전히 필요하면 최신 upstream/main에서 단일 목적 브랜치로 깨끗하게 다시 추출하겠습니다. stale PR로 닫습니다.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant