Skip to content

feat: improve sync code#20

Open
caiodomingues wants to merge 2 commits intoisabellaherman:mainfrom
caiodomingues:fix/sync
Open

feat: improve sync code#20
caiodomingues wants to merge 2 commits intoisabellaherman:mainfrom
caiodomingues:fix/sync

Conversation

@caiodomingues
Copy link
Copy Markdown
Contributor

Summary

  • Re-enable auto-sync that was disabled due to ~400k GitHub API requests/hour
  • Add 3-layer safeguards to prevent API abuse: client-side cooldown (30min), server-side cooldown (5min), and GitHub
    rate limit pre-check (<50 remaining → skip)
  • Replace window.location.reload() with in-place leaderboard refresh
  • Add BroadcastChannel to prevent duplicate syncs across browser tabs

Copilot AI review requested due to automatic review settings March 7, 2026 00:09
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 7, 2026

@caiodomingues is attempting to deploy a commit to the isabellaherman's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR re-enables the auto-sync feature for XP data that was previously disabled due to excessive GitHub API requests (~400k/hour). It introduces a 3-layer safeguard system: client-side localStorage-based cooldown (30 min), server-side database cooldown (5 min), and GitHub rate limit pre-check (skip if <50 remaining). It also replaces the page reload approach with in-place leaderboard refresh and adds cross-tab sync deduplication via BroadcastChannel.

Changes:

  • Added rate limit pre-check in syncUserData to skip syncs when GitHub API quota is low
  • Added server-side cooldown in the force-sync API route to return cached data when the last update was less than 5 minutes ago
  • Replaced the commented-out auto-sync with a properly guarded implementation using client-side cooldown, cross-tab deduplication, and in-place leaderboard refresh

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/xp-calculator.ts Adds GitHub rate limit pre-check before performing sync API calls
app/api/force-sync/route.ts Adds server-side 5-minute cooldown using lastXpUpdate field
app/page.tsx Replaces disabled auto-sync with guarded implementation (30-min client cooldown, BroadcastChannel cross-tab dedup, in-place leaderboard refresh)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/xp-calculator.ts Outdated
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.

2 participants