Skip to content

Added dynamic profile stats And 1 hr In-Memory Cache#69

Open
SampurnaNiyogi wants to merge 2 commits intoAvishkarPatil:mainfrom
SampurnaNiyogi:fix/68
Open

Added dynamic profile stats And 1 hr In-Memory Cache#69
SampurnaNiyogi wants to merge 2 commits intoAvishkarPatil:mainfrom
SampurnaNiyogi:fix/68

Conversation

@SampurnaNiyogi
Copy link

Description

This PR addresses issue #68, which replaces static/mock profile activity data with dynamically fetched GitHub statistics. Previously, the profile page displayed hardcoded values for all users, which was misleading and did not reflect actual GitHub activity.

With this change, profile statistics are now fetched from GitHub APIs via the backend and rendered dynamically on the profile page.


Solution

Backend

  • Added a new endpoint:
    GET /api/v1/github/stats/{username}
  • Updated existing GitHub-related service logic to support fetching real profile statistics.
  • Fetches real data using official GitHub APIs:
    • Pull Requests count
      Retrieved using GitHub Search API:
      author:{username} type:pr
    • Closed Issues count
      Retrieved using GitHub Search API:
      author:{username} type:issue is:closed
      (issues authored by the user)
    • Total Stars received
      Aggregated from the user’s public repositories
    • Total Contribution Count
      Retrieved using GitHub GraphQL API (aggregated contribution data)
  • Implemented in-memory caching with a 1-hour TTL to minimize GitHub API calls and avoid rate-limit issues.
  • Returns a structured JSON response optimized for frontend consumption.

In-memory caching was intentionally used to keep the solution lightweight and avoid introducing additional infrastructure dependencies.


Frontend

  • Updated the profile page to fetch statistics from the new backend endpoint.
  • Removed hardcoded values from mockData.stats.
  • Updated the stats section to display dynamic values for:
    • Pull requests
    • Issues closed
    • Contributions-related metrics
  • Added a new “Stars” section to the profile stats UI, which was previously missing.
  • Integrated the new stats without breaking existing layout or user experience.

Testing

  • Verified backend API responses using authenticated GitHub requests.
  • Confirmed correct rendering of dynamic stats on the profile page.
  • Manually tested repeated requests to ensure caching behavior works as expected.

Future Improvements

  • Introduce Redis-based caching for production or horizontally scaled deployments.
  • Fetch contribution activity using GitHub’s REST Events API to display detailed, event-level contribution data and replace the remaining static activity placeholders.

Related Issue

Closes #68

Copy link
Collaborator

@Rahma5983 Rahma5983 left a comment

Choose a reason for hiding this comment

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

@SampurnaNiyogi The implementation is functionally correct and well-structured. It successfully replaces the misleading hardcoded stats with real data as requested in issue #68.
@AvishkarPatil You can merge the PR and if you want you can also check it once, or else it is good to go

@Arsh123344423
Copy link
Collaborator

I have found a few problems :-

  1. What if starred repo is more than 100.
  2. in get_user_stats the entire async with httpx.async.client() as client function is under try block which doesn't manage proper error handling.
    Rest your code is fine.
    fix these issues and we are sorted.

@SampurnaNiyogi
Copy link
Author

Ok I'll check into it. Thank you..

@Arsh123344423
Copy link
Collaborator

Saw the changes looks fine @AvishkarPatil This PR is ready to be merged.

Copy link
Collaborator

@Arsh123344423 Arsh123344423 left a comment

Choose a reason for hiding this comment

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

Looks fine now

@AvishkarPatil
Copy link
Owner

I'll merge it by EOD

@SampurnaNiyogi
Copy link
Author

Fixed the problem for more than 100 starred repos using iteration through response Link headers until all available pages are requested for paginated Github response.
And also modified the error handling in get_user_stats.

@AvishkarPatil AvishkarPatil added SWoC26 Social Winter of Code 2026 SWOC Part of Social Winter of Code Medium Requires some experience labels Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Medium Requires some experience SWOC Part of Social Winter of Code SWoC26 Social Winter of Code 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants