Skip to content

Refactor GitHub service for improved caching and error handling#99

Open
rudrakshtank wants to merge 1 commit into
AOSSIE-Org:mainfrom
rudrakshtank:issue98
Open

Refactor GitHub service for improved caching and error handling#99
rudrakshtank wants to merge 1 commit into
AOSSIE-Org:mainfrom
rudrakshtank:issue98

Conversation

@rudrakshtank

@rudrakshtank rudrakshtank commented Jul 3, 2026

Copy link
Copy Markdown

Addressed Issues:

Fixes #98

Checklist

  • My code follows the project's code style and conventions
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contributing Guidelines

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • New Features

    • Improved GitHub data fetching with better support for request cancellation and optional inclusion of pull requests in issue lists.
    • Enhanced handling of authenticated requests, helping the app work more reliably with personal access tokens.
  • Bug Fixes

    • Improved caching and data refresh behavior for faster, more consistent results.
    • Added clearer handling for rate limits, access errors, and unavailable resources, reducing unexpected failures.

@github-actions github-actions Bot added enhancement New feature or request javascript JavaScript/TypeScript changes size/L 201-500 lines changed first-time-contributor First time contributor labels Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The GitHub service module is reworked to use a token-aware IndexedDB cache with TTL, retry/cleanup handling, and separate get/set/delete helpers. Fetch requests now use versioned headers, Bearer auth, safe JSON parsing, structured error objects, and options/signal support across all exported fetch functions.

Changes

GitHub fetch caching and error handling rework

Layer / File(s) Summary
IndexedDB connection and cache CRUD primitives
src/services/github.js
Caches the DB connection, handles open/upgrade/block/error/versionchange events, and adds cacheGet, cacheSet, cacheDelete, cacheClear with TTL enforcement and non-blocking expired-entry deletion.
Token fingerprinting and cache key generation
src/services/github.js
Adds fallbackHash, tokenFingerprint() (crypto.subtle with fallback), and makeCacheKey(url, pat) to derive per-token cache keys.
Request headers, rate-limit parsing, and structured errors
src/services/github.js
Switches to Authorization: Bearer, adds GitHub API versioning header, numberHeader(), browser-safe emitRateLimitUpdate, readJsonSafe(), and createGithubError() attaching status/body/rate-limit fields.
Core fetchWithCache orchestration
src/services/github.js
Reworks fetchWithCache to compute token-scoped cache keys, check L2 cache, fetch with signal support, update rate-limit state, parse responses safely, throw structured errors for 401/403/404/429, and write back to cache non-blockingly.
Exported fetch function updates with options/signal support
src/services/github.js
Updates fetchOrg, fetchRepos, fetchContributors, fetchIssues, fetchRateLimit to accept options, propagate signal for cancellation, adjust pagination when pat is set without a finite repoCount, and filter pull requests via includePullRequests in fetchIssues.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • AOSSIE-Org/OrgExplorer#89: Both PRs modify src/services/github.js's GitHub fetch helpers—especially fetchRepos, fetchContributors, and fetchIssues—changing how PAT affects pagination/aggregation and call signatures.

Suggested labels: Typescript Lang

Suggested reviewers: Zahnentferner, bhavik-mangla

Poem

A rabbit dug a cache so deep,
With tokens hashed and TTLs to keep,
Bearer tokens now unlock the door,
Errors structured, rate-limits galore,
Hop, fetch, cancel — signals fly,
This burrow's fast as carrots fly! 🥕🐇

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: improved GitHub service caching and error handling.
Linked Issues check ✅ Passed The changes align with #98 by adding IndexedDB caching, token-aware reads/writes, rate-limit updates, PAT auth, and shared fetch options.
Out of Scope Changes check ✅ Passed No clearly unrelated changes stand out; the additions stay within GitHub fetching, caching, auth, and error-handling scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size/L 201-500 lines changed and removed size/L 201-500 lines changed labels Jul 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/github.js`:
- Around line 28-35: The IndexedDB connection cached by dbPromise is not being
reset when db.onversionchange closes the database, so later cacheGet/cacheSet
calls keep reusing a closed handle and fail. Update the db.onversionchange
handler in the open DB flow to clear dbPromise before closing the db, so the
next cache access in the GitHub service opens a fresh connection instead of
reusing the stale one.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 182a475a-ff65-4f11-914e-9c2937ddd5b5

📥 Commits

Reviewing files that changed from the base of the PR and between d904719 and 876af9b.

📒 Files selected for processing (1)
  • src/services/github.js

Comment thread src/services/github.js
Comment on lines +28 to +35
req.onsuccess = e => {
const db = e.target.result

// Close old connection if a newer DB version is opened elsewhere.
db.onversionchange = () => db.close()

resolve(db)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

git ls-files src/services/github.js
wc -l src/services/github.js
cat -n src/services/github.js | sed -n '1,220p'
printf '\n--- dbPromise usages ---\n'
rg -n "\bdbPromise\b|onversionchange|indexedDB\.open|transaction\(" src/services/github.js

Repository: AOSSIE-Org/OrgExplorer

Length of output: 6988


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "\bdbPromise\b|onversionchange|indexedDB\.open" src

Repository: AOSSIE-Org/OrgExplorer

Length of output: 623


🏁 Script executed:

#!/bin/bash
set -euo pipefail

node - <<'JS'
const vm = require('vm');

console.log('Node version:', process.version);
console.log('IndexedDB in globalThis:', 'indexedDB' in globalThis);
JS

Repository: AOSSIE-Org/OrgExplorer

Length of output: 214


Reset dbPromise on versionchange. Closing the handle leaves the resolved promise cached, so later cacheGet/cacheSet calls keep reusing a closed DB and fail with InvalidStateError, effectively disabling the cache for the rest of the session. Clear dbPromise when db.onversionchange fires so the next access opens a fresh connection.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/github.js` around lines 28 - 35, The IndexedDB connection cached
by dbPromise is not being reset when db.onversionchange closes the database, so
later cacheGet/cacheSet calls keep reusing a closed handle and fail. Update the
db.onversionchange handler in the open DB flow to clear dbPromise before closing
the db, so the next cache access in the GitHub service opens a fresh connection
instead of reusing the stale one.

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

Labels

enhancement New feature or request first-time-contributor First time contributor javascript JavaScript/TypeScript changes size/L 201-500 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Improved GitHub API Fetching with IndexedDB Caching

1 participant