Conversation
Increases cache revalidate timeout to 24h and adds robust Cache-Control headers to the `ImageResponse` to take advantage of Edge/CDN caching. Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request increases the revalidation period for GitHub user data to 24 hours and adds a Cache-Control header to the Open Graph image response. The feedback suggests replacing magic numbers with calculations to improve readability and ensure consistency across the caching configuration.
src/app/api/og/[username]/route.tsx
Outdated
| const res = await fetch(`https://api.github.com/users/${encodeURIComponent(username)}`, { | ||
| headers: { Accept: "application/vnd.github.v3+json" }, | ||
| next: { revalidate: 600 }, | ||
| next: { revalidate: 86400 }, |
There was a problem hiding this comment.
To improve readability and avoid magic numbers, it's better to express 86400 as a calculation. This makes the intent (24 hours) clear at a glance. Ideally, this value would be a shared constant used here and in the Cache-Control header to ensure consistency.
| next: { revalidate: 86400 }, | |
| next: { revalidate: 24 * 60 * 60 }, |
| headers: { | ||
| "Cache-Control": "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400", | ||
| }, |
There was a problem hiding this comment.
To avoid magic numbers and improve readability, it's better to use calculations for cache durations. This also makes it easier to see that the s-maxage and stale-while-revalidate values are consistent with the revalidate option for the data fetch.
For better maintainability, consider defining these durations as constants at the top of the file and reusing them.
| headers: { | |
| "Cache-Control": "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400", | |
| }, | |
| headers: { | |
| "Cache-Control": "public, max-age=" + (60 * 60) + ", s-maxage=" + (24 * 60 * 60) + ", stale-while-revalidate=" + (24 * 60 * 60), | |
| }, |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 17 minutes and 17 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughOG画像生成APIでGitHubユーザー取得のrevalidateを600→86400秒に拡張し、生成するImageResponseに対して 変更内容
コード審査の予想時間🎯 2 (Simple) | ⏱️ ~10 minutes ラビットの詩
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/app/api/og/`[username]/route.tsx:
- Around line 31-33: The fetch call that requests GitHub user data (the variable
res fetching `https://api.github.com/users/${encodeURIComponent(username)}`)
should include a User-Agent header to match src/lib/github.ts; update the
headers object in that fetch to add "User-Agent": "github-user-summary"
alongside Accept and next so the GitHub API receives the recommended User-Agent
value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 10dfda90-a775-4b33-a89d-a5a373dcae67
📒 Files selected for processing (1)
src/app/api/og/[username]/route.tsx
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed both comments in : switched to and added to the GitHub fetch request (commit ). Added ❤️ reactions and resolved addressed threads. |
Acknowledged. |
Increases cache revalidate timeout to 24h and adds robust Cache-Control headers to the `ImageResponse` to take advantage of Edge/CDN caching. Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
Add GitHub User-Agent header and replace cache magic numbers with named constants for readability and consistency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Deployment failed with the following error: Learn More: https://vercel.com/hirokis-projects-afd618c7?upgradeToPro=build-rate-limit |
|
Addressed the review feedback and pushed commit
Could you please re-review this PR? |
Acknowledged. |
Increases cache revalidate timeout to 24h and adds robust Cache-Control headers to the `ImageResponse` to take advantage of Edge/CDN caching. Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/app/api/og/[username]/route.tsx (1)
22-24:⚠️ Potential issue | 🟡 Minor
GitHub APIリクエストにUser-Agentヘッダーを再追加してください。Line 22-24 の fetch で
User-Agentが未設定です。以前の指摘と同様、ここはsrc/lib/github.tsと揃えて"User-Agent": "github-user-summary"を入れるべきです。🔧 修正案
- const res = await fetch(`https://api.github.com/users/${encodeURIComponent(username)}`, { - headers: { Accept: "application/vnd.github.v3+json" }, + const res = await fetch(`https://api.github.com/users/${encodeURIComponent(username)}`, { + headers: { + Accept: "application/vnd.github.v3+json", + "User-Agent": "github-user-summary", + }, next: { revalidate: 86400 }, });Based on learnings:
src/lib/github.ts : Preserve timeout handling, use "User-Agent: github-user-summary", and use encodeURIComponent(username) when constructing GitHub API paths in src/lib/github.ts.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/app/api/og/`[username]/route.tsx around lines 22 - 24, The GitHub API fetch in route.tsx is missing the required User-Agent header; update the fetch call that requests https://api.github.com/users/${encodeURIComponent(username)} (in the API route handler) to include "User-Agent": "github-user-summary" alongside the existing Accept header and next revalidate option so headers remain { Accept: "application/vnd.github.v3+json", "User-Agent": "github-user-summary" } and behavior matches src/lib/github.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/app/api/og/`[username]/route.tsx:
- Line 24: Extract the hard-coded TTL numbers into named constants (e.g.,
DAILY_CACHE_TTL = 86400 and HOURLY_CACHE_TTL = 3600) declared near the top of
the module and replace all numeric occurrences (for example the next: {
revalidate: 86400 } object and the other place using 3600) with those constants
so TTLs are centrally managed and reusable; ensure imports/exports are adjusted
if the constants need to be used elsewhere in this file or module.
---
Duplicate comments:
In `@src/app/api/og/`[username]/route.tsx:
- Around line 22-24: The GitHub API fetch in route.tsx is missing the required
User-Agent header; update the fetch call that requests
https://api.github.com/users/${encodeURIComponent(username)} (in the API route
handler) to include "User-Agent": "github-user-summary" alongside the existing
Accept header and next revalidate option so headers remain { Accept:
"application/vnd.github.v3+json", "User-Agent": "github-user-summary" } and
behavior matches src/lib/github.ts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 34f5e7bf-bb84-42f5-bf06-3a332de80f49
📒 Files selected for processing (1)
src/app/api/og/[username]/route.tsx
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
💡 What:
Increased
next.revalidatecache duration from 600s to 86400s (24 hours) for the initialfetchinsidesrc/app/api/og/[username]/route.tsx. AddedCache-Controlheaderpublic, max-age=3600, s-maxage=86400, stale-while-revalidate=86400to the returnedImageResponse.🎯 Why:
The GitHub user API was being hit frequently by bots (e.g. Discord, Twitter) for OG image previews, leading to potential GitHub API rate limiting due to the short 10-minute caching. OG Images for basic profile data rarely change rapidly, making longer caching beneficial. Returning HTTP
Cache-Controlheaders also offloads caching to the Next.js Cache / CDN, lowering CPU load for serverless image generation significantly.📊 Measured Improvement:
We expect lower baseline resource consumption, fewer
RateLimitErrorhits to the GitHub API, and decreased edge compute time for OG generation since we now take full advantage of CDN/Edge caching using proper headers. A local benchmark (node benchmark.js) originally failed continuously hitting rate limits/fetch errors under load since revalidation fired repeatedly, but withs-maxage=86400CDNs will handle concurrency better without invoking the edge function constantly.PR created automatically by Jules for task 7917588998097144516 started by @is0692vs