Skip to content

Feature/add global ranking#120

Open
Yashaswini-K-P wants to merge 9 commits into
codepvg:mainfrom
Yashaswini-K-P:feature/add-global-ranking
Open

Feature/add global ranking#120
Yashaswini-K-P wants to merge 9 commits into
codepvg:mainfrom
Yashaswini-K-P:feature/add-global-ranking

Conversation

@Yashaswini-K-P
Copy link
Copy Markdown
Contributor

@Yashaswini-K-P Yashaswini-K-P commented Jun 7, 2026

Description

This PR extends the /api/student/:username endpoint by adding the user's live LeetCode Global Ranking to the API response payload.

Previously, while problem metrics were tracked historically via GitHub repositories, the absolute global leaderboard ranking was not exposed to the student profile layout. This change fetches the most recent global ranking dynamically from the LeetCode API, updates the response body structure gracefully, and implements zero-value fallbacks if the upstream service is unreachable—ensuring complete backward compatibility.

Linked Issue

Fixes #92

Changes Made

  • Direct API Upstream Fetching: Configured fetchStudentHistory to initially hit the leetcode-api-dun.vercel.app wrapper to capture the live, un-mutated ranking integer on-demand.
  • Resilient Graceful Degradation: Added fallback error handling to default the ranking parameter to 0 or retrieve it sequentially from historical repositories if the upstream wrapper times out or fails.
  • Payload Extension: Modified the return utility signature to inject the root-level ranking key directly alongside username and history data to align with frontend consumption criteria.

Type of Change

  • Bug fix
  • New feature
  • UI/Visual update
  • Documentation update
  • Refactor

Testing

  • Tested locally
  • Tested on mobile viewport (if applicable)
  • No console errors introduced

Checklist

  • My code follows the project's coding style
  • I have formatted my code locally using Prettier
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have updated documentation if required
  • I have linked the relevant issue

Screenshots / Screen Recording

Screenshot 2026-06-07 134024

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

A maintainer will review your submission shortly.

Copy link
Copy Markdown
Collaborator

@jagdish-15 jagdish-15 left a comment

Choose a reason for hiding this comment

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

Since we already depend on the same API wrapper for the sync workflow itself, if the API fails badly enough for ranking to become unavailable, the leaderboard sync/update process would already have much larger issues anyway. Because of that, the historical snapshot fallback mechanism feels a bit overengineered for this use case.

The fetch-student-info.js changes themselves make sense for this issue, but I don’t think the additional sync-leaderboard.js modifications and storing ranking inside the leaderboard snapshot JSON files are really necessary here.

I’d suggest simplifying this by keeping the fetch-student-info.js changes, directly returning apiData.ranking || 0, removing the part where it tries to fetch the rank from historical data when the API fails, and removing the additional sync-leaderboard.js changes and ranking persistence from leaderboard JSON generation entirely.

That would keep the implementation much cleaner and more aligned with the original issue scope.

@Yashaswini-K-P Yashaswini-K-P requested a review from jagdish-15 June 8, 2026 16:53
Comment on lines +83 to +85
if (ranking === null || ranking === 0) {
ranking = user.ranking || 0;
}
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.

Suggested change
if (ranking === null || ranking === 0) {
ranking = user.ranking || 0;
}

@@ -1,5 +1,3 @@
"use strict";

const axios = require("axios");
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.

Suggested change
const axios = require("axios");
"use strict";
const axios = require("axios");

I think you accidentally removed this while resolving the conflicts. Please always check the final diffs provided by GitHub after resolving merge conflicts to ensure no unrelated changes were accidentally removed in the process.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Global Ranking to /api/student/:username Response

2 participants