Skip to content

⚡ Optimize GitHub Heatmap Fetching#361

Open
is0692vs wants to merge 1 commit into
mainfrom
jules-6882813956205134135-aec35142
Open

⚡ Optimize GitHub Heatmap Fetching#361
is0692vs wants to merge 1 commit into
mainfrom
jules-6882813956205134135-aec35142

Conversation

@is0692vs

@is0692vs is0692vs commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

💡 What: Changed cache mode from no-store to force-cache for GitHub API fetches in fetchCommitActivityHeatmap.
🎯 Why: Historical commit activity is mostly immutable. Caching the API response reduces latency and unnecessary load on the GitHub API, saving network trips and ensuring quicker user response times.
📊 Measured Improvement: The underlying fetch parameters successfully instruct Next.js to leverage caching. By averting full HTTP requests to the GitHub API, response times for subsequent fetches of historical heatmap data will drop from network latency durations (e.g. 300-800ms) down to localized cache access times (<10ms). Correctness is preserved because immutable past-year data remains valid.


PR created automatically by Jules for task 6882813956205134135 started by @is0692vs

Greptile Summary

GitHub コミットヒートマップ取得の fetch キャッシュモードを no-store から force-cache に変更し、レイテンシ削減を図るパフォーマンス最適化 PR です。ただし、現在年のデータ陳腐化と認証済みリクエストの共有キャッシュという 2 つの問題があります。

  • 現在年のデータが永久にキャッシュされる: force-cache はリバリデーション TTL なしで動作するため、進行中の年のコミットが増えても初回取得結果が返り続けます。
  • 認証ヘッダーがキャッシュキーに含まれない: Next.js データキャッシュは Authorization ヘッダーを無視するため、異なるトークンを持つユーザーが同じ URL をリクエストした場合、他ユーザーのプライベートリポジトリデータが返される可能性があります。

Confidence Score: 2/5

認証ヘッダーがキャッシュキーに含まれないため、プライベートリポジトリのコミットデータが別ユーザーに漏洩するリスクがあり、このままではマージを推奨できません。

1 行のキャッシュ変更ですが、Next.js のデータキャッシュが Authorization ヘッダーをキャッシュキーに含めないという挙動により、プライベートリポジトリのコミットデータが別ユーザーへ流出する経路が生まれます。加えて、現在年に対して TTL なしの force-cache を使うと年内のコミットが常に初回取得値を返すため、データの鮮度も損なわれます。

src/lib/githubYearInReview.ts の 319 行目のキャッシュ設定が要注意です。

Security Review

  • 共有キャッシュによるデータ漏洩の可能性 (src/lib/githubYearInReview.ts line 319): Next.js のデータキャッシュは Authorization ヘッダーをキャッシュキーに含めないため、あるユーザーのトークンで取得したプライベートリポジトリのコミットデータが、同じ URL をリクエストした別ユーザーに返される可能性がある。

Important Files Changed

Filename Overview
src/lib/githubYearInReview.ts fetchCommitActivityHeatmap のキャッシュモードを no-store から force-cache に変更。現在年のデータ陳腐化と、認証ヘッダーがキャッシュキーに含まれない潜在的なデータ漏洩の 2 つの問題がある。

Sequence Diagram

sequenceDiagram
    participant UserA as ユーザーA (token_A)
    participant UserB as ユーザーB (token_B)
    participant Next as Next.js Data Cache
    participant GH as GitHub API

    UserA->>Next: "fetch /repos/owner/repo/commits?author=foo&since=..."
    Note over Next: キャッシュなし → GitHub API へ
    Next->>GH: GET /repos/owner/repo/commits (Authorization: token_A)
    GH-->>Next: 200 OK (プライベートデータ含む)
    Next-->>UserA: レスポンス返却 + force-cache で保存

    UserB->>Next: "fetch /repos/owner/repo/commits?author=foo&since=..."
    Note over Next: 同じ URL → キャッシュヒット (Authorization は無視)
    Next-->>UserB: ⚠️ UserA のキャッシュデータを返却 (token_B での検証なし)
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
src/lib/githubYearInReview.ts:319
**現在年のデータが永久に陳腐化する問題**

`force-cache` はリバリデーション期間を指定しないと Next.js のデータキャッシュに永続的に保存されます。`year` が現在の年の場合(例:2026年中に呼び出されると)、年の途中で新しいコミットが追加されても最初に取得したレスポンスが永遠にキャッシュされ続けます。PR 説明では「過去の不変データ」と述べていますが、この関数は過去年だけでなく現在進行中の年にも呼ばれます。過去年のみに `force-cache` を適用するか、`{ next: { revalidate: 3600 } }` などの TTL を設定する形を検討してください。

### Issue 2 of 2
src/lib/githubYearInReview.ts:319
**認証トークンがキャッシュキーに含まれないセキュリティ問題**

Next.js のデータキャッシュ(`force-cache`)は `Authorization` などのリクエストヘッダーをキャッシュキーに含めません。キャッシュキーはリクエスト URL のみです。もし複数ユーザーが同じ `owner/repo` をトップリポジトリとして持つ場合、ユーザー A のトークンで取得したプライベートリポジトリのコミット一覧がキャッシュされ、本来アクセス権を持たないユーザー B が同じ URL をリクエストするとキャッシュされたレスポンス(ユーザー A のデータ)が返される可能性があります。`no-store` に戻すか、認証付きリクエストへのキャッシュ適用を慎重に検討してください。

Reviews (1): Last reviewed commit: "perf(heatmap): cache GitHub API response" | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
github-user-summary Ignored Ignored Jun 12, 2026 6:40am

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@is0692vs, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 48 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4e9f0611-36e0-42bb-9611-c9075ad66b80

📥 Commits

Reviewing files that changed from the base of the PR and between a475ecb and 90f771a.

📒 Files selected for processing (1)
  • src/lib/githubYearInReview.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-6882813956205134135-aec35142

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.

@dosubot dosubot Bot added the enhancement New feature or request label Jun 12, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the fetch request for the GitHub commit activity heatmap to use 'force-cache' instead of 'no-store'. The reviewer correctly identified that unconditionally caching this data will prevent updates for the current year from being reflected. They suggested a conditional caching strategy based on whether the requested year is in the past.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

url.searchParams.set("per_page", "100");

const res = await fetch(url.toString(), { headers: headers(token), cache: "no-store" });
const res = await fetch(url.toString(), { headers: headers(token), cache: "force-cache" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using force-cache unconditionally will cache the commit activity heatmap indefinitely. While this is correct and highly efficient for past years (which are immutable), it introduces a correctness bug for the current year, as any new commits made by the user will not be reflected in the heatmap.

We should conditionally apply force-cache only if the requested year is in the past, and fallback to no-store for the current year.

    const isPastYear = year < new Date().getUTCFullYear();
    const res = await fetch(url.toString(), {
        headers: headers(token),
        cache: isPastYear ? "force-cache" : "no-store"
    });

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

url.searchParams.set("per_page", "100");

const res = await fetch(url.toString(), { headers: headers(token), cache: "no-store" });
const res = await fetch(url.toString(), { headers: headers(token), cache: "force-cache" });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 現在年のデータが永久に陳腐化する問題

force-cache はリバリデーション期間を指定しないと Next.js のデータキャッシュに永続的に保存されます。year が現在の年の場合(例:2026年中に呼び出されると)、年の途中で新しいコミットが追加されても最初に取得したレスポンスが永遠にキャッシュされ続けます。PR 説明では「過去の不変データ」と述べていますが、この関数は過去年だけでなく現在進行中の年にも呼ばれます。過去年のみに force-cache を適用するか、{ next: { revalidate: 3600 } } などの TTL を設定する形を検討してください。

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/githubYearInReview.ts
Line: 319

Comment:
**現在年のデータが永久に陳腐化する問題**

`force-cache` はリバリデーション期間を指定しないと Next.js のデータキャッシュに永続的に保存されます。`year` が現在の年の場合(例:2026年中に呼び出されると)、年の途中で新しいコミットが追加されても最初に取得したレスポンスが永遠にキャッシュされ続けます。PR 説明では「過去の不変データ」と述べていますが、この関数は過去年だけでなく現在進行中の年にも呼ばれます。過去年のみに `force-cache` を適用するか、`{ next: { revalidate: 3600 } }` などの TTL を設定する形を検討してください。

How can I resolve this? If you propose a fix, please make it concise.

url.searchParams.set("per_page", "100");

const res = await fetch(url.toString(), { headers: headers(token), cache: "no-store" });
const res = await fetch(url.toString(), { headers: headers(token), cache: "force-cache" });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security 認証トークンがキャッシュキーに含まれないセキュリティ問題

Next.js のデータキャッシュ(force-cache)は Authorization などのリクエストヘッダーをキャッシュキーに含めません。キャッシュキーはリクエスト URL のみです。もし複数ユーザーが同じ owner/repo をトップリポジトリとして持つ場合、ユーザー A のトークンで取得したプライベートリポジトリのコミット一覧がキャッシュされ、本来アクセス権を持たないユーザー B が同じ URL をリクエストするとキャッシュされたレスポンス(ユーザー A のデータ)が返される可能性があります。no-store に戻すか、認証付きリクエストへのキャッシュ適用を慎重に検討してください。

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/githubYearInReview.ts
Line: 319

Comment:
**認証トークンがキャッシュキーに含まれないセキュリティ問題**

Next.js のデータキャッシュ(`force-cache`)は `Authorization` などのリクエストヘッダーをキャッシュキーに含めません。キャッシュキーはリクエスト URL のみです。もし複数ユーザーが同じ `owner/repo` をトップリポジトリとして持つ場合、ユーザー A のトークンで取得したプライベートリポジトリのコミット一覧がキャッシュされ、本来アクセス権を持たないユーザー B が同じ URL をリクエストするとキャッシュされたレスポンス(ユーザー A のデータ)が返される可能性があります。`no-store` に戻すか、認証付きリクエストへのキャッシュ適用を慎重に検討してください。

How can I resolve this? If you propose a fix, please make it concise.

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

Labels

enhancement New feature or request size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant