Skip to content

Commit a8dd6ea

Browse files
ulemonsclaude
andcommitted
feat: implement busFactor1Only filter (CM-1220)
Filter packages to only those with a single maintainer. Uses a correlated subquery backed by the UNIQUE(package_id, maintainer_id) index on package_maintainers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 3f9a965 commit a8dd6ea

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

backend/src/api/public/v1/packages/listPackages.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ const querySchema = z.object({
2121
pageSize: z.coerce.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),
2222
ecosystem: z.string().trim().optional(),
2323
lifecycle: z.enum(lifecycleValues).optional(), // TODO: filter not yet implemented in DAL
24-
busFactor1Only: booleanQueryParam.refine((v) => !v, {
25-
message: 'busFactor1Only filter is not yet implemented',
26-
}),
24+
busFactor1Only: booleanQueryParam,
2725
staleOnly: booleanQueryParam,
2826
unstewardedOnly: booleanQueryParam,
2927
sortBy: z.enum(['name', 'health', 'impact', 'openVulns']).default('name'),
@@ -53,6 +51,7 @@ export async function listPackages(req: Request, res: Response): Promise<void> {
5351
ecosystem,
5452
staleOnly,
5553
unstewardedOnly,
54+
busFactor1Only,
5655
sortBy: effectiveSortBy,
5756
sortDir,
5857
})

services/libs/data-access-layer/src/osspckgs/api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface ListPackagesOptions {
6666
ecosystem?: string
6767
staleOnly: boolean
6868
unstewardedOnly: boolean
69+
busFactor1Only: boolean
6970
sortBy: 'name' | 'impact' | 'openVulns'
7071
sortDir: 'asc' | 'desc'
7172
}
@@ -94,6 +95,13 @@ export async function listPackagesForApi(
9495
conditions.push(`(s.status = 'unassigned' OR s.id IS NULL)`)
9596
}
9697

98+
if (opts.busFactor1Only) {
99+
// UNIQUE(package_id, maintainer_id) on package_maintainers covers this lookup
100+
conditions.push(
101+
`(SELECT COUNT(*) FROM package_maintainers pm WHERE pm.package_id = p.id) = 1`,
102+
)
103+
}
104+
97105
const where = `WHERE ${conditions.join(' AND ')}`
98106

99107
// health is a v2 field — fall back to name sort

0 commit comments

Comments
 (0)