Skip to content

[Backend] Fix fetch-student-info.js Stopping Entire History Collection on First Missing Day #181

@rishab11250

Description

@rishab11250

Description

The scripts/fetch-student-info.js file collects a user's LeetCode submission history by fetching daily JSON snapshots from a data repository. It loops through a date range (default 365 days) and makes parallel fetch() calls via Promise.all().

The bug: If a user did not submit any solution on a particular day (e.g., weekends, holidays), the daily snapshot for that date does not exist. The current fetch() implementation treats a 404 response as a hard failure — the entire Promise.all() rejects, and the function returns an empty history array. This means if a user skipped even one day in the past year, their entire history graph shows as empty.

Additionally, the script fires 100+ concurrent fetch requests in a single Promise.all() — this will trigger rate limiting on raw.githubusercontent.com and cause all requests to fail.


Proposed Solution

Fix 1 — Missing days should be skipped, not fatal:

  1. Replace Promise.all() with Promise.allSettled() so individual 404 failures don't reject the entire batch.
  2. For each settled promise, only include the result if it was fulfilled and returned valid data.
  3. Log skipped dates at console.warn level (not error) for observability.

Fix 2 — Reduce concurrency to avoid rate limiting:

  1. Implement a concurrency limiter — process fetches in chunks of 10-15 at a time instead of 100+.
  2. Add a small delay (200-300ms) between chunks to be respectful to the upstream API.

Fix 3 — Validate response status explicitly:

  1. Before parsing JSON, check response.ok. If !response.ok, treat as "no data for this day" (not an error) and skip the date.

Acceptance Criteria

  • A user with gaps in their submission history still gets a complete (but sparser) history graph.
  • 404 responses for individual dates are logged as warnings and skipped — they do not block remaining dates.
  • Concurrent fetch count is reduced to a maximum of 15 simultaneous requests.
  • A small delay is added between batches.
  • The history graph on the user profile page renders correctly for users with gaps.
  • Script output clearly distinguishes between "no data" days and actual errors.

Affected Files

  • scripts/fetch-student-info.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions