github-profile-analyzer icon indicating copy to clipboard operation
github-profile-analyzer copied to clipboard

[codex] cache profile analyses

Open saurabhhhcodes opened this issue 5 months ago โ€ข 1 comments

What changed

  • Added an SWR-backed fetch layer for profile analyses so repeated navigations reuse cached responses instead of refetching GitHub data every mount.
  • Moved the API call into a shared helper that normalizes errors, handles the star-gate response, and supports force refreshes.
  • Wired the existing refresh buttons through the cached mutate path so manual refreshes update the same cache entry.

Why

  • This issue calls out repeated GitHub API requests. The profile page was doing a local fetch in the client component on remount, so the same username could trigger the analysis again even when the app already had the result.

Validation

  • npm run lint
  • npm run build (passed after supplying the repo's required local environment variables)

Summary by CodeRabbit

  • Improvements
    • Enhanced profile analysis fetching with better error handling and messaging
    • More reliable profile refresh and analysis updates

saurabhhhcodes avatar Jun 11 '26 12:06 saurabhhhcodes

Review Change Stack

๐Ÿ“ Walkthrough

Walkthrough

This PR integrates SWR for profile analysis fetching. A new profile-analysis.ts module exports ProfileAnalysisError, ProfileAnalysisOptions, and fetchProfileAnalysis() function. ProfileClient now uses useSWR instead of manual state, gated by username validation, with refresh callbacks and error/modal handling.

Changes

SWR Integration for Profile Analysis

Layer / File(s) Summary
Profile Analysis Fetch Module
src/lib/profile-analysis.ts
New module exports ProfileAnalysisError class (carrying status and code), ProfileAnalysisOptions type with force/nosave flags, buildProfileUrl helper that constructs /api/analyze URLs with query parameters, and fetchProfileAnalysis function that performs no-store fetch, parses JSON defensively, throws ProfileAnalysisError for 403 "Star required" or any non-OK response, and returns parsed result.
ProfileClient SWR Integration Setup
package.json, src/app/[username]/ProfileClient.tsx
Add swr dependency, import useSWR hook and new fetchProfileAnalysis/ProfileAnalysisError, establish state for error/showStarModal/isRefreshing, compute safeUsername with invalid-username gating, wire useSWR with fallbackData and custom options, attach effects to synchronize modal/error state from SWR errors and dismiss modal when fresh data arrives.
ProfileClient Refresh and Error Handling
src/app/[username]/ProfileClient.tsx
Implement refreshAnalysis callback that calls fetchProfileAnalysis and updates SWR via mutate, with error handling that shows star-modal on STAR_REQUIRED code or sets error state otherwise, resets isRefreshing in finally block; add username validation effect that sets error when invalid.
ProfileClient Refresh Event Handlers
src/app/[username]/ProfileClient.tsx
Update handleRecheckStar to call refreshAnalysis() after delay, update ownership/identity effect to use safeUsername, change "See Latest Analysis" button to refreshAnalysis({ force: true, nosave: true }), change "Force Refresh" button to refreshAnalysis({ force: true }).

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~20 minutes

Poem

๐Ÿฐ SWR swoops in with caching grace, The profile analysis finds its place, State and stale-while-revalidate dance, Fresh data flows in every glance, A rabbit's refactor, smooth and bright! โœจ

๐Ÿšฅ Pre-merge checks | โœ… 4 | โŒ 1

โŒ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% 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
Title check โœ… Passed The title '[codex] cache profile analyses' clearly summarizes the main change: implementing caching via SWR for profile analysis results to avoid repeated fetches.
Description check โœ… Passed The description covers what changed, why it was needed, and validation steps performed; required sections are addressed despite not following the exact template format.
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.

โœ๏ธ Tip: You can configure your own custom pre-merge checks in the settings.

โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests

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.

coderabbitai[bot] avatar Jun 11 '26 12:06 coderabbitai[bot]