Skip to content

perf: add CDN Cache-Control headers to streak API route - #267

Merged
JhaSourav07 merged 4 commits into
JhaSourav07:mainfrom
HarshParmar029:fix/cdn-cache-headers
May 24, 2026
Merged

perf: add CDN Cache-Control headers to streak API route#267
JhaSourav07 merged 4 commits into
JhaSourav07:mainfrom
HarshParmar029:fix/cdn-cache-headers

Conversation

@HarshParmar029

@HarshParmar029 HarshParmar029 commented May 22, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #69

Added CDN Cache-Control headers to the streak API route:

  • Replaced dynamic s-maxage with fixed s-maxage=14400 (4 hours)
  • Added stale-while-revalidate=86400 (24 hours)
  • Updated error responses (500) to use public, s-maxage=60

Pillar

🛠️ Other (Bug fix, refactoring, docs)

Checklist

  • I have read the CONTRIBUTING.md file.
  • My commits follow the Conventional Commits format.
  • I have made sure that I have only one commit to merge in this PR.

@vercel

vercel Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

@HarshParmar029 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @HarshParmar029, welcome to CommitPulse! 🎉

Thanks for opening your first pull request — this is a big deal and we appreciate the effort!

While you wait for a review, please double-check:

  • ✅ You've read the CONTRIBUTING.md checklist
  • npm run lint, npm run format, and npm run test all pass locally
  • ✅ Your PR has a visual preview if it touches any SVG output
  • 💬 You've joined our Discord for faster PR feedback

A maintainer will review your PR shortly. Hang tight! 🚀

@github-actions github-actions Bot added the needs-details This PR is missing required description details. label May 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @HarshParmar029, it looks like you didn't use our PR template!

The section ## Description is missing from your PR description.

Please update your PR description to include all required sections so we can review this properly:

  • ## Description — What does this PR do? Which issue does it fix?
  • ## Pillar — Which contribution pillar does this fall under?
  • ## Checklist — Have you ticked off the quality checklist?

You can find the full template in CONTRIBUTING.md. Just edit your PR description and the needs-details label will be removed automatically. 🙌

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label May 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Hey @HarshParmar029, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run format:check   # Check Prettier formatting
npm run lint           # Run ESLint
npm run typecheck      # TypeScript type check
npm run test           # Run unit tests (Vitest)
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run format         # Auto-fix formatting with Prettier
npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@github-actions github-actions Bot removed the needs-details This PR is missing required description details. label May 22, 2026
@Aamod007

Copy link
Copy Markdown
Collaborator

@HarshParmar029 follow PR #87 for further contributions in the repo

@github-actions github-actions Bot added the needs-rebase This PR has merge conflicts and needs a rebase. label May 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

8 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@HarshParmar029
HarshParmar029 force-pushed the fix/cdn-cache-headers branch from 1390e5b to 9eb5837 Compare May 23, 2026 15:50
@vercel

vercel Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

There is no GitHub account connected to this Vercel account.

@HarshParmar029
HarshParmar029 force-pushed the fix/cdn-cache-headers branch from 6f906cb to 35f50c8 Compare May 23, 2026 15:56
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

Comment thread .github/workflows/ci.yml Outdated
run: npm run build
env:
CI: false
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why did you edited this ?
keep the PR focused to solve the issue please

@HarshParmar029
HarshParmar029 force-pushed the fix/cdn-cache-headers branch from 35f50c8 to 1f66636 Compare May 23, 2026 18:32
@HarshParmar029

Copy link
Copy Markdown
Contributor Author

Fixed! Removed the extra FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 line from ci.yml and squashed all commits into one. PR is now focused only on CDN Cache-Control headers.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @HarshParmar029, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@HarshParmar029
HarshParmar029 force-pushed the fix/cdn-cache-headers branch 4 times, most recently from 6bcadb0 to a1ed434 Compare May 23, 2026 20:25
@JhaSourav07 JhaSourav07 added mentor:Aamod007 and removed gssoc:approved PR has been reviewed and accepted for valid contribution points labels May 24, 2026
@HarshParmar029
HarshParmar029 force-pushed the fix/cdn-cache-headers branch from 884df70 to 2827302 Compare May 24, 2026 12:12
@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label May 24, 2026
@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label May 24, 2026
@HarshParmar029

Copy link
Copy Markdown
Contributor Author

"Hi @Aamod007, Fixed all issues:
✅ Restored getSecondsUntilUTCMidnight and getSecondsUntilMidnightInTimezone — dynamic cache TTL working correctly
✅ Error responses (404/500) use no-cache
✅ Success responses use public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400
✅ All 205 tests passing
✅ escapeXML preserved
Could you please re-review,

Thank you!"

Copilot AI left a comment

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.

Pull request overview

This PR is intended to implement CDN-friendly Cache-Control headers for the /api/streak route to reduce repeated serverless invocations and GitHub API usage (Fixes #69).

Changes:

  • Removes/adjusts in-file comments and whitespace in app/api/streak/route.ts.
  • (Intended, per PR description/issue #69) Update caching strategy for successful and error responses, but the current diff does not yet apply the described s-maxage=14400 behavior.
Comments suppressed due to low confidence (1)

app/api/streak/route.ts:103

  • The Cache-Control logic here still uses a dynamic s-maxage=${secondsToMidnight} (until midnight) rather than the fixed s-maxage=14400 described in the PR and required by issue #69. As a result, the response header won’t match the expected public, s-maxage=14400, stale-while-revalidate=86400 value, and the related cache-control tests will also need updating to reflect the new fixed TTL.
    const secondsToMidnight = tzParam
      ? getSecondsUntilMidnightInTimezone(timezone)
      : getSecondsUntilUTCMidnight();
    const cacheControl =
      refresh || isRandomTheme
        ? 'no-cache, no-store, must-revalidate'
        : `public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400`;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/api/streak/route.ts
@HarshParmar029

Copy link
Copy Markdown
Contributor Author

Hi @Aamod007, Updated 500 error response to Cache-Control: public, s-maxage=60 as suggested by Copilot. All 205 tests passing. Could you please re-review? Thank you!

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

app/api/streak/route.ts:104

  • The PR description/Issue #69 calls for a fixed CDN cache TTL (s-maxage=14400) on successful responses, but the route still computes secondsToMidnight and sets s-maxage dynamically based on UTC/local midnight. This doesn't match the described behavior (and the current tests are still written around the midnight-based TTL).
    const secondsToMidnight = tzParam
      ? getSecondsUntilMidnightInTimezone(timezone)
      : getSecondsUntilUTCMidnight();
    const cacheControl =
      refresh || isRandomTheme
        ? 'no-cache, no-store, must-revalidate'
        : `public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400`;

Comment thread app/api/streak/route.test.ts

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ready to merge

@Aamod007
Aamod007 requested a review from Copilot May 24, 2026 13:55
@JhaSourav07
JhaSourav07 merged commit d28919b into JhaSourav07:main May 24, 2026
10 checks passed
@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label May 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @HarshParmar029! Your PR has been successfully merged. 🚀

Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.

⚠️ Important for GSSoC Contributors:
You are strictly advised to join our Discord Server as it is mandatory for all GSSoC participants. All important announcements, point claims, and community discussions happen there.

Keep building! 💻✨

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

app/api/streak/route.ts:104

  • The success response Cache-Control is still using a dynamic s-maxage=${secondsToMidnight}. The PR description/issue #69 call for a fixed s-maxage=14400 (4 hours) with stale-while-revalidate=86400; as-is the route won’t match the intended CDN caching behavior (and requires the midnight helper calculations).
    const secondsToMidnight = tzParam
      ? getSecondsUntilMidnightInTimezone(timezone)
      : getSecondsUntilUTCMidnight();
    const cacheControl =
      refresh || isRandomTheme
        ? 'no-cache, no-store, must-revalidate'
        : `public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400`;

Comment thread app/api/streak/route.ts
Comment on lines 135 to 142
@@ -152,6 +142,7 @@
},
Comment thread app/api/streak/route.ts
Comment on lines 155 to 161
return new NextResponse(errorSvg, {
status: 500,
headers: {
'Content-Type': 'image/svg+xml',
'Cache-Control': 'no-cache',
'Cache-Control': 'public, s-maxage=60',
},
});
Comment on lines 342 to 348
it('never caches an error response', async () => {
vi.mocked(fetchGitHubContributions).mockRejectedValue(new Error('Network failure'));

const response = await GET(makeRequest({ user: 'octocat' }));

expect(response.headers.get('Cache-Control')).toBe('no-cache');
expect(response.headers.get('Cache-Control')).toBe('public, s-maxage=60');
});
@github-actions github-actions Bot added the type:performance Code changes that improve performance/speed label May 24, 2026
arywk40-hue pushed a commit to arywk40-hue/commitpulse that referenced this pull request May 27, 2026
)

## Description
Fixes JhaSourav07#69

Added CDN Cache-Control headers to the streak API route:
- Replaced dynamic s-maxage with fixed `s-maxage=14400` (4 hours)
- Added `stale-while-revalidate=86400` (24 hours)
- Updated error responses (500) to use `public, s-maxage=60`

## Pillar
🛠️ Other (Bug fix, refactoring, docs)

## Checklist
- [x] I have read the CONTRIBUTING.md file.
- [x] My commits follow the Conventional Commits format.
- [x] I have made sure that I have only one commit to merge in this PR.
@JhaSourav07 JhaSourav07 added gssoc:approved PR has been reviewed and accepted for valid contribution points and removed gssoc:approved PR has been reviewed and accepted for valid contribution points labels Jun 17, 2026
MasterJi27 pushed a commit to MasterJi27/commitpulse that referenced this pull request Jul 4, 2026
)

## Description
Fixes JhaSourav07#69

Added CDN Cache-Control headers to the streak API route:
- Replaced dynamic s-maxage with fixed `s-maxage=14400` (4 hours)
- Added `stale-while-revalidate=86400` (24 hours)
- Updated error responses (500) to use `public, s-maxage=60`

## Pillar
🛠️ Other (Bug fix, refactoring, docs)

## Checklist
- [x] I have read the CONTRIBUTING.md file.
- [x] My commits follow the Conventional Commits format.
- [x] I have made sure that I have only one commit to merge in this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved PR has been reviewed and accepted for valid contribution points GSSoC 2026 level:beginner Small changes Usually isolated fixes or simple UI/text updates. mentor:Aamod007 quality:exceptional Outstanding contribution with exceptional implementation quality, testing. type:performance Code changes that improve performance/speed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance: Implement CDN Cache-Control headers for the API

4 participants