Skip to content

fix(services): add in-memory caching to Codeforces and CodeChef services - #542

Open
Rajen5145 wants to merge 1 commit into
SamXop123:mainfrom
Rajen5145:fix-codeforces-codechef-caching
Open

fix(services): add in-memory caching to Codeforces and CodeChef services#542
Rajen5145 wants to merge 1 commit into
SamXop123:mainfrom
Rajen5145:fix-codeforces-codechef-caching

Conversation

@Rajen5145

Copy link
Copy Markdown

Description

Summary of Changes

Implements in-memory caching using githubCache in the Codeforces and CodeChef services to prevent hitting external API rate limits (e.g., Codeforces HTTP 429 errors) and reduce proxy load on rapid dashboard refreshes.

Motivation / Context

  • Resolves Missing caching mechanism in Codeforces and CodeChef services leading to API rate-limiting #154
  • Unlike GitHub and LeetCode services, Codeforces and CodeChef previously made live API requests on every invocation.
  • Codeforces strictly enforces a rate limit of 1 request per 2 seconds, which caused HTTP 429 failures during concurrent or repeated profile views.
  • CodeChef queries an external proxy (competeapi.vercel.app), which risked IP blocking and latency overhead without caching.

Key Modifications

  • src/services/codeforces.service.js:
    • Added validation for missing handle.
    • Implemented cache check (codeforces:${handle}) prior to fetching data.
    • Stored successful responses in githubCache.
  • src/services/codechef.service.js:
    • Added validation for missing handle.
    • Implemented cache check (codechef:${handle}) prior to fetching data.
    • Stored successful responses in githubCache.
  • src/services/tests/codechef.service.test.js & src/services/tests/codeforces.service.test.js:
    • Added beforeEach hook calling githubCache.clear() to ensure isolated test execution across multiple mocked scenarios.

Verification & Testing

  • Ran test suite locally via npm test.
  • All 19 test suites and 322 individual tests passed.
  • Verified that consecutive queries for the same handle return cached responses.

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown

@Rajen5145 is attempting to deploy a commit to the Dot_NotSam's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Missing caching mechanism in Codeforces and CodeChef services leading to API rate-limiting

1 participant