Repository navigation
fix: load watchable repos in the background and cache them #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,38 @@ export async function saveWatchedRepos(repos: WatchedRepo[]): Promise<void> { | |
| await chrome.storage.local.set({ [REPOS_KEY]: repos }); | ||
| } | ||
|
|
||
| // === Available repos cache === | ||
| // The full list of repos the user *could* watch. Fetching it is slow (personal | ||
| // repos + every org's repos, across each connected platform), so the background | ||
| // service worker fetches it and caches the result here. The Repos page renders | ||
| // from this cache instantly and lets the refresh run in the background — which | ||
| // means it survives the popup being closed. See issue #23. | ||
|
|
||
| export const AVAILABLE_REPOS_CACHE_KEY = 'pr_radar_available_repos'; | ||
|
|
||
| export interface AvailableRepo { | ||
| platform: Platform; | ||
| fullName: string; | ||
| } | ||
|
|
||
| export interface AvailableReposCache { | ||
| repos: AvailableRepo[]; | ||
| updatedAt: number; | ||
| // Set only when nothing could be loaded (every connected account errored), so | ||
| // the popup can show an error instead of an endless spinner. A partial failure | ||
| // still caches the repos that did load and leaves this undefined. | ||
| error?: string; | ||
| } | ||
|
|
||
| export async function getCachedAvailableRepos(): Promise<AvailableReposCache | null> { | ||
| const result = await chrome.storage.local.get(AVAILABLE_REPOS_CACHE_KEY); | ||
| return result[AVAILABLE_REPOS_CACHE_KEY] ?? null; | ||
| } | ||
|
|
||
| export async function saveCachedAvailableRepos(cache: AvailableReposCache): Promise<void> { | ||
| await chrome.storage.local.set({ [AVAILABLE_REPOS_CACHE_KEY]: cache }); | ||
| } | ||
|
|
||
|
Comment on lines
+105
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Move These are domain types (analogous to ♻️ Suggested move--- a/src/shared/types.ts
+++ b/src/shared/types.ts
+export interface AvailableRepo {
+ platform: Platform;
+ fullName: string;
+}
+
+export interface AvailableReposCache {
+ repos: AvailableRepo[];
+ updatedAt: number;
+ error?: string;
+}--- a/src/shared/storage.ts
+++ b/src/shared/storage.ts
-export interface AvailableRepo {
- platform: Platform;
- fullName: string;
-}
-
-export interface AvailableReposCache {
- repos: AvailableRepo[];
- updatedAt: number;
- // Set only when nothing could be loaded ...
- error?: string;
-}
+import type { AvailableRepo, AvailableReposCache } from './types';As per path instructions, "In TypeScript source files, use the shared 🤖 Prompt for AI AgentsSource: Path instructions |
||
| // === PR cache === | ||
|
|
||
| import type { PullRequest } from './types'; | ||
|
|
@@ -211,6 +243,7 @@ export async function clearAll(): Promise<void> { | |
| POLL_ERRORS_DISMISSED_KEY, | ||
| RATE_LIMIT_DISMISSED_KEY, | ||
| AI_SUMMARY_CACHE_KEY, | ||
| AVAILABLE_REPOS_CACHE_KEY, | ||
| ]); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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:
Repository: deployhq/pr-radar
Length of output: 2286
🏁 Script executed:
Repository: deployhq/pr-radar
Length of output: 21325
🏁 Script executed:
Repository: deployhq/pr-radar
Length of output: 20501
Add a timeout to the available-repos refresh
doRefreshAvailableRepos()already handles per-account API failures, butsrc/shared/api/github.ts,src/shared/api/gitlab.ts, andsrc/shared/api/bitbucket.tsstill use plainfetch()with no timeout/abort path. One stalled request can leaveFETCH_AVAILABLE_REPOSpending and the popup stuck inrefreshing; wrap those calls (or the popupsendMessage) with anAbortController/timeout so the refresh fails closed.🤖 Prompt for AI Agents