Skip to content

Commit 580e733

Browse files
betegonclaude
authored andcommitted
fix: skip already-searched orgs on findProjectsBySlug fallthrough
When the cached-orgs fast path finds no projects and falls through to the full listOrganizations() path, avoid re-searching orgs that already returned 404 by filtering them out with a Set lookup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 70d1730 commit 580e733

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/lib/api/projects.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ export async function findProjectsBySlug(
215215
// from `sentry issue list` output — which already called listOrganizations()
216216
// and populated org_regions with all accessible orgs.
217217
const cachedOrgRegions = await getAllOrgRegions();
218-
if (cachedOrgRegions.size > 0) {
219-
const cachedSlugs = [...cachedOrgRegions.keys()];
218+
const cachedSlugs = [...cachedOrgRegions.keys()];
219+
if (cachedSlugs.length > 0) {
220220
const cachedResults = await searchOrgs(cachedSlugs);
221221
const cachedProjects = extractProjects(cachedResults);
222222
if (cachedProjects.length > 0) {
@@ -225,9 +225,13 @@ export async function findProjectsBySlug(
225225
// Fall through: project might be in a new org not yet cached
226226
}
227227

228-
// Full listing: fetch all orgs from API, then search each
228+
// Full listing: fetch all orgs from API, then skip already-searched cached orgs
229229
const orgs = await listOrganizations();
230-
const searchResults = await searchOrgs(orgs.map((o) => o.slug));
230+
const cachedSet = new Set(cachedSlugs);
231+
const newOrgSlugs = orgs
232+
.filter((o) => !cachedSet.has(o.slug))
233+
.map((o) => o.slug);
234+
const searchResults = await searchOrgs(newOrgSlugs);
231235

232236
return {
233237
projects: extractProjects(searchResults),

0 commit comments

Comments
 (0)