Skip to content

feat(votes): cache getAllTasksWithVoteInfo and add CDN cache-control for anonymous requests#3709

Merged
KATO-Hiro merged 3 commits into
stagingfrom
#3708
Jun 21, 2026
Merged

feat(votes): cache getAllTasksWithVoteInfo and add CDN cache-control for anonymous requests#3709
KATO-Hiro merged 3 commits into
stagingfrom
#3708

Conversation

@KATO-Hiro

@KATO-Hiro KATO-Hiro commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

close #3708

Summary by CodeRabbit

リリースノート

  • パフォーマンス改善

    • 投票情報がキャッシュされるようになり、ページの読み込み速度が向上しました。
    • ブラウザのキャッシュ制御が最適化されました。
  • バグ修正

    • 投票情報の取得に失敗した場合、ページは空の状態で正常に表示されるようになりました。

KATO-Hiro and others added 3 commits June 21, 2026 03:53
…for anonymous requests

- Add getCachedAllTasksWithVoteInfo() to votes server cache (10min TTL)
- Extend invalidateVoteCaches() to clear the new cache entry
- Wrap getAllTasksWithVoteInfo() in the cache in vote_statistics.ts
- Invalidate vote caches on createTask() / updateTask() (task grade affects estimatedGrade)
- Set public s-maxage=300 stale-while-revalidate=600 for anonymous /votes responses
- Skip CDN header on degraded responses to avoid pinning broken pages at CDN
- Add page_server.test.ts covering header and data return for anonymous/logged-in/degraded cases

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…w notes

- Remove `as unknown as import('@prisma/client').TaskGrade` casts in cache.test.ts
  (TaskGrade from '$lib/types/task' is directly assignable)
- Rename dataOk → fetchFailed and invert condition for positive-default readability
- Simplify load() type annotation: Awaited<ReturnType<...>> → TaskWithVoteInfo[]
- Add result!. non-null assertions in page_server.test.ts to satisfy SvelteKit's
  void | PageData inference on load() return type
- Add review.md summarising findings (0 critical/high, 5 nit fixes applied)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… branch completion

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fb121b47-8a3b-45f4-a72d-4c6c864686a7

📥 Commits

Reviewing files that changed from the base of the PR and between 5aff85c and b6491fb.

📒 Files selected for processing (8)
  • src/features/votes/server/cache.test.ts
  • src/features/votes/server/cache.ts
  • src/features/votes/services/vote_statistics.test.ts
  • src/features/votes/services/vote_statistics.ts
  • src/lib/services/tasks.ts
  • src/routes/votes/+page.server.ts
  • src/routes/votes/page_server.test.ts
  • src/test/lib/services/tasks.test.ts

📝 Walkthrough

Walkthrough

投票キャッシュ層に getCachedAllTasksWithVoteInfo を追加し、getAllTasksWithVoteInfo がキャッシュ経由で動作するよう変更。タスク作成・更新時に投票キャッシュを無効化し、投票ページの load 関数にエラーフォールバックと条件付き Cache-Control ヘッダー設定を追加。

Changes

投票キャッシュ拡張と投票ページの堅牢化

Layer / File(s) Summary
vote キャッシュ実装の整理と拡張
src/features/votes/server/cache.ts
キャッシュインスタンスを voteStatsCache / allTasksWithVoteInfoCache の2つに分割。getCachedAllTasksWithVoteInfo を新規追加し、invalidateVoteCaches / disposeVoteCaches が両キャッシュを対象とするよう変更。
getAllTasksWithVoteInfo をキャッシュ経由に変更
src/features/votes/services/vote_statistics.ts, src/features/votes/services/vote_statistics.test.ts
DB 集約ロジックを fetchAllTasksWithVoteInfo に分離し、getAllTasksWithVoteInfogetCachedAllTasksWithVoteInfo(fetchAllTasksWithVoteInfo) を返すように変更。テストモックに getCachedAllTasksWithVoteInfo を追加。
タスク変更時に vote キャッシュを無効化
src/lib/services/tasks.ts, src/test/lib/services/tasks.test.ts
createTaskupdateTask の成功パスで invalidateVoteCaches() を追加。テストで成功/失敗ケースごとに呼び出し有無を検証。
votes ページ load のエラーフォールバックと Cache-Control
src/routes/votes/+page.server.ts, src/routes/votes/page_server.test.ts
getAllTasksWithVoteInfo 呼び出しを try/catch でラップし、失敗時は空配列フォールバックと fetchFailed フラグを設定。未ログインかつ取得成功時のみ setHeadersCache-Control を設定。テストを新規追加し各ケースを検証。
cache.test.ts の更新
src/features/votes/server/cache.test.ts
makeTasksWithVoteInfo / mockTasksFn を追加し、getCachedAllTasksWithVoteInfo の委譲・キャッシュ効果テストを追加。invalidateVoteCaches テストをタスク投票情報キャッシュの再フェッチ検証へ置き換え。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🗳️ タスク更新でキャッシュも一掃、
CDN にも優しくパスを届ける。
失敗しても空配列で微笑み、
ヘッダーはそっと匿名へ贈る。
✨ 投票ページ、今日も軽やかに走る。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトルは投票ページのキャッシング機能とCDNキャッシュ制御という2つの主要変更を正確に反映しており、変更内容と完全に一致している。
Linked Issues check ✅ Passed PR目標はissue #3708(投票ページにCDN/サーバ側キャッシュを付与)と完全に一致し、サーバキャッシュ実装(10分TTL)とCDNヘッダ設定が実装されている。
Out of Scope Changes check ✅ Passed すべての変更がissue #3708に直結するキャッシング機能、キャッシュ無効化、CDN最適化に限定されており、範囲外の変更は認められない。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 #3708

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 and usage tips.

@KATO-Hiro KATO-Hiro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KATO-Hiro KATO-Hiro merged commit 40f183b into staging Jun 21, 2026
3 checks passed
@KATO-Hiro KATO-Hiro deleted the #3708 branch June 21, 2026 05:30
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.

[perf] 投票ページ の共有データに対して CDN / サーバ側のキャッシュを付与しましょう

1 participant