Skip to content

perf(api): derive past usage dates in one pass - #447

Closed
seonghobae wants to merge 2 commits into
developmentalfrom
perf/events-past-date-one-pass
Closed

perf(api): derive past usage dates in one pass#447
seonghobae wants to merge 2 commits into
developmentalfrom
perf/events-past-date-one-pass

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 15, 2026

Copy link
Copy Markdown

Summary

  • extracts the usagePerTurn past-date invalidation logic into a documented helper;
  • derives de-duplicated UTC day-start ISO timestamps in one pass instead of chained map → filter → map allocations;
  • adds focused regression coverage for empty input, duplicate timestamps, Korea-time/UTC boundary behavior, today/future exclusion, and invalid timestamp handling.

Why this replaces the unique part of #399

PR #399 was stale, non-mergeable, and mixed a bot journal with chart and API optimizations. The chart-side date parsing is now owned by PR #425, which carries a current-base test and the formatRelativeTimeFromMs contract. This PR preserves only the API-route delta on exact current developmental without the .jules artifact or chart churn.

Issues are disabled in this repository, so the remaining API work could not be preserved as a tracking issue before closing #399.

Behavior contract

The helper preserves existing endpoint semantics:

  • duplicate timestamps on the same UTC day collapse to one ISO day-start value;
  • Korea-time timestamps are normalized by UTC date, matching the old getUTC* logic;
  • today and future UTC days are excluded from cache invalidation;
  • invalid timestamps are ignored because they produce NaN and fail the ms < todayMs test, as in the previous callback path.

Verification

The PR is test-first in effect for the extracted contract: new focused derivePastUsageDateIsoStrings tests describe the behavior before the production route uses the helper. Hosted CI, central OpenCode coverage evidence, SAST/Semgrep, Security Scan, dependency review, and current-head review must run on this exact head before merge.

Merge gate

Merge only after exact-head CI, central OpenCode coverage evidence, SAST/Semgrep, Security Scan, dependency review, current-head review, zero unresolved actionable threads, and all live branch-protection rules pass. No check or review evidence from #399 transfers.

Summary by CodeRabbit

  • 버그 수정

    • 과거 사용량 날짜를 UTC 기준으로 정확히 계산하도록 개선했습니다.
    • 오늘 및 미래 날짜, 잘못된 타임스탬프가 과거 사용량에 포함되지 않습니다.
    • 중복 날짜를 제거해 캐시 무효화 처리가 안정적으로 동작합니다.
  • 테스트

    • 빈 입력, 날짜 중복, 한국 시간대 타임스탬프 등 주요 사례에 대한 검증을 추가했습니다.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c709a82-419b-49a0-b586-c461a3fe2073

📥 Commits

Reviewing files that changed from the base of the PR and between 1c1a161 and f2c919a.

📒 Files selected for processing (2)
  • packages/web/src/app/api/events/route.test.ts
  • packages/web/src/app/api/events/route.ts

📝 Walkthrough

Walkthrough

사용량 타임스탬프에서 과거 UTC 날짜를 도출하는 로직을 내보내기 함수로 추출했다. POST 처리에서 해당 함수를 사용한다. 빈 입력, 중복 제거, 시간대 변환, 날짜 필터링, 잘못된 타임스탬프 처리를 테스트한다.

Changes

과거 사용량 날짜 처리

Layer / File(s) Summary
UTC 과거 날짜 헬퍼와 POST 연결
packages/web/src/app/api/events/route.ts
사용량 타임스탬프에서 오늘 이전의 고유한 UTC 날짜 시작 ISO 문자열을 생성하는 derivePastUsageDateIsoStrings를 추가했다. POST는 인라인 계산 대신 이 헬퍼를 호출한다.
날짜 도출 동작 테스트
packages/web/src/app/api/events/route.test.ts
빈 입력, UTC 날짜별 중복 제거, 한국 시간대 타임스탬프 변환, 오늘 및 미래 날짜 제외, 잘못된 타임스탬프 무시를 검증한다.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to f2c91

This change consolidates past usage-date derivation while preserving the documented API behavior and adding focused regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: claude, greatsumini

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 과거 사용량 날짜를 한 번에 도출하도록 변경한 핵심 내용을 명확하고 간결하게 설명합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 perf/events-past-date-one-pass

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Author

Closing this PR as a duplicate of the stronger current-base canonical lane #446. After #447 was opened, the live PR sweep showed #446 already preserves the same server-side portion of #399 with a cleaner package boundary: collectPastUtcDates lives under packages/web/src/lib/server/usage-date-buckets.ts, returns Date[] directly for Prisma invalidation, handles invalid timestamps explicitly, and includes leap-day / ordering / timezone regression tests.

Keeping both would split one API optimization across competing branches. #446 should be the owner; it needs its PR body updated from the initial RED-stage wording, exact-head CI/security/coverage/review, and ready-for-review only after the current implementation is verified. No checks or review evidence from #447 transfers.

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