33 *
44 * Provides a warm/consume pattern for org resolution during `sentry init`.
55 * Call {@link warmOrgDetection} early (before the preamble) to start DSN
6- * scanning and org-list fetching in the background. Later, call
7- * {@link resolveOrgPrefetched} or {@link listOrgsPrefetched} — they return
8- * the cached result instantly if the background work has finished, or
9- * fall back to a live call if it hasn't been warmed.
6+ * scanning in the background. Later, call {@link resolveOrgPrefetched} —
7+ * it returns the cached result instantly if the background work has
8+ * finished, or falls back to a live call if it hasn't been warmed.
9+ *
10+ * `listOrganizations()` does NOT need prefetching because it has its own
11+ * SQLite cache layer (PR #446). After `sentry login`, the org cache is
12+ * pre-populated (PR #490), so subsequent calls return from cache instantly
13+ * without any HTTP requests. Only `resolveOrg()` (DSN scanning) benefits
14+ * from background prefetching since it performs filesystem I/O.
1015 *
1116 * This keeps the hot path (inside the wizard's `createSentryProject`)
1217 * free of explicit promise-threading — callers just swap in the
1318 * prefetch-aware functions.
1419 */
1520
16- import { listOrganizations } from "../api-client.js" ;
1721import type { ResolvedOrg } from "../resolve-target.js" ;
1822import { resolveOrg } from "../resolve-target.js" ;
1923
2024type OrgResult = ResolvedOrg | null ;
21- type OrgListResult = Array < { id : string ; slug : string ; name : string } > ;
2225
2326let orgPromise : Promise < OrgResult > | undefined ;
24- let orgListPromise : Promise < OrgListResult > | undefined ;
2527
2628/**
27- * Kick off background org detection and org-list fetching .
29+ * Kick off background DSN scanning + env var / config checks .
2830 *
2931 * Safe to call multiple times — subsequent calls are no-ops.
3032 * Errors are silently swallowed so the foreground path can retry.
@@ -33,9 +35,6 @@ export function warmOrgDetection(cwd: string): void {
3335 if ( ! orgPromise ) {
3436 orgPromise = resolveOrg ( { cwd } ) . catch ( ( ) => null ) ;
3537 }
36- if ( ! orgListPromise ) {
37- orgListPromise = listOrganizations ( ) . catch ( ( ) => [ ] ) ;
38- }
3938}
4039
4140/**
@@ -49,21 +48,9 @@ export function resolveOrgPrefetched(cwd: string): Promise<OrgResult> {
4948 return resolveOrg ( { cwd } ) . catch ( ( ) => null ) ;
5049}
5150
52- /**
53- * List organizations, using the prefetched result if available.
54- * Falls back to a live call when {@link warmOrgDetection} was not called.
55- */
56- export function listOrgsPrefetched ( ) : Promise < OrgListResult > {
57- if ( orgListPromise ) {
58- return orgListPromise ;
59- }
60- return listOrganizations ( ) . catch ( ( ) => [ ] ) ;
61- }
62-
6351/**
6452 * Reset prefetch state. Used by tests to prevent cross-test leakage.
6553 */
6654export function resetPrefetch ( ) : void {
6755 orgPromise = undefined ;
68- orgListPromise = undefined ;
6956}
0 commit comments