Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/lib/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import type {
SentryProject,
} from "../../types/index.js";

import { cacheProjectsForOrg } from "../db/project-cache.js";
import {
cacheProjectsForOrg,
setCachedProject,
setCachedProjectByDsnKey,
} from "../db/project-cache.js";
import { getCachedOrganizations } from "../db/regions.js";
import { parseDsn } from "../dsn/parser.js";
import { type AuthGuardSuccess, withAuthGuard } from "../errors.js";
import { logger } from "../logger.js";
import { getApiBaseUrl } from "../sentry-client.js";
Expand Down Expand Up @@ -190,6 +195,32 @@ export async function createProjectWithDsn(
const project = await createProject(orgSlug, teamSlug, body);
const dsn = await tryGetPrimaryDsn(orgSlug, project.slug);
const url = buildProjectUrl(orgSlug, project.slug);

// Seed project_cache so the next command doesn't re-resolve via API
try {
const parsed = dsn ? parseDsn(dsn) : null;
if (parsed?.orgId) {
setCachedProject(parsed.orgId, parsed.projectId, {
orgSlug,
orgName: orgSlug,
projectSlug: project.slug,
projectName: project.name,
projectId: project.id,
});
}
if (parsed?.publicKey) {
setCachedProjectByDsnKey(parsed.publicKey, {
orgSlug,
orgName: orgSlug,
projectSlug: project.slug,
projectName: project.name,
projectId: project.id,
});
}
} catch {
// Best-effort — cache failure should not break project creation
}

return { project, dsn, url };
}

Expand Down
13 changes: 13 additions & 0 deletions src/lib/init/wizard-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,19 @@ export async function runWizard(initialOptions: WizardOptions): Promise<void> {
}

handleFinalResult(result, spin, spinState);

// Eagerly populate dsn_cache so the next command doesn't re-scan files.
// The DSN is now in source code (written by apply-patchset), so detectDsn
// will find it and cache with the correct projectRoot and sourcePath.
// project_cache was already seeded by createProjectWithDsn.
if (!dryRun) {
try {
const { detectDsn } = await import("../dsn/index.js");
await detectDsn(directory);
} catch {
// Best-effort — cache seeding failure doesn't affect init result
}
}
}

function handleFinalResult(
Expand Down
Loading