Refactor GitHub service for improved caching and error handling#99
Refactor GitHub service for improved caching and error handling#99rudrakshtank wants to merge 1 commit into
Conversation
WalkthroughThe 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 ChangesGitHub fetch caching and error handling rework
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/services/github.js
| 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) | ||
| } |
There was a problem hiding this comment.
🩺 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.jsRepository: AOSSIE-Org/OrgExplorer
Length of output: 6988
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "\bdbPromise\b|onversionchange|indexedDB\.open" srcRepository: 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);
JSRepository: 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.
Addressed Issues:
Fixes #98
Checklist
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
Bug Fixes