-
-
Notifications
You must be signed in to change notification settings - Fork 4
perf(init): run org detection in background during preamble #443
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e06faf
perf(init): run org detection in background during preamble
MathurAditya724 cc9b33f
refactor: use prefetch module instead of threading promises
MathurAditya724 cb52098
refactor: drop listOrgsPrefetched — listOrganizations() is SQLite-cached
BYK a2749ad
fix: guard prefetch against cwd mismatch
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * Background Org Detection Prefetch | ||
| * | ||
| * Provides a warm/consume pattern for org resolution during `sentry init`. | ||
| * Call {@link warmOrgDetection} early (before the preamble) to start DSN | ||
| * scanning in the background. Later, call {@link resolveOrgPrefetched} — | ||
| * it returns the cached result instantly if the background work has | ||
| * finished, or falls back to a live call if it hasn't been warmed. | ||
| * | ||
| * `listOrganizations()` does NOT need prefetching because it has its own | ||
| * SQLite cache layer (PR #446). After `sentry login`, the org cache is | ||
| * pre-populated (PR #490), so subsequent calls return from cache instantly | ||
| * without any HTTP requests. Only `resolveOrg()` (DSN scanning) benefits | ||
| * from background prefetching since it performs filesystem I/O. | ||
| * | ||
| * This keeps the hot path (inside the wizard's `createSentryProject`) | ||
| * free of explicit promise-threading — callers just swap in the | ||
| * prefetch-aware functions. | ||
| */ | ||
|
|
||
| import type { ResolvedOrg } from "../resolve-target.js"; | ||
| import { resolveOrg } from "../resolve-target.js"; | ||
|
|
||
| type OrgResult = ResolvedOrg | null; | ||
|
|
||
| let orgPromise: Promise<OrgResult> | undefined; | ||
| let warmedCwd: string | undefined; | ||
|
|
||
| /** | ||
| * Kick off background DSN scanning + env var / config checks. | ||
| * | ||
| * Safe to call multiple times — subsequent calls are no-ops. | ||
| * Errors are silently swallowed so the foreground path can retry. | ||
| */ | ||
| export function warmOrgDetection(cwd: string): void { | ||
| if (!orgPromise) { | ||
| warmedCwd = cwd; | ||
| orgPromise = resolveOrg({ cwd }).catch(() => null); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Resolve the org, using the prefetched result if available. | ||
| * | ||
| * Returns the cached background result only when `cwd` matches the | ||
| * directory that was passed to {@link warmOrgDetection}. If `cwd` | ||
| * differs (or warming was never called), falls back to a live | ||
| * `resolveOrg()` call so callers always get results for the correct | ||
| * working directory. | ||
| */ | ||
| export function resolveOrgPrefetched(cwd: string): Promise<OrgResult> { | ||
| if (orgPromise && cwd === warmedCwd) { | ||
| return orgPromise; | ||
| } | ||
| return resolveOrg({ cwd }).catch(() => null); | ||
| } | ||
|
|
||
| /** | ||
| * Reset prefetch state. Used by tests to prevent cross-test leakage. | ||
| */ | ||
| export function resetPrefetch(): void { | ||
| orgPromise = undefined; | ||
| warmedCwd = undefined; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.