Skip to content

perf(npm-registry,scanner): include publishedAt in fix version resolutions to avoid redundant resolveVersionPublishDate call - #742

Merged
sonukapoor merged 4 commits into
OWASP:mainfrom
luojiyin1987:perf/avoid-redundant-fix-version-lookup
Jun 23, 2026
Merged

sonukapoor merged 4 commits into
OWASP:mainfrom
luojiyin1987:perf/avoid-redundant-fix-version-lookup

Conversation

@luojiyin1987

@luojiyin1987 luojiyin1987 commented Jun 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #741

Problem

In validateDirectFixTargets, both resolvePublishedFixVersion and resolveVersionPublishDate fetch the same packument for the same package. resolvePublishedFixVersion already has the packument in scope — it could also read packument.time[version] and return the publish date, avoiding the second resolveVersionPublishDate call (packument cache lookup + time access + cache write).

Changes

  • Extended PublishedFixVersionResolution with publishedAt: string | null
  • resolvePublishedFixVersion: added publishedAt to all return paths
  • resolveLowestKnownNonVulnerableVersion: added publishedAt to success return paths
  • Removed attachFixVersionPublishDate helper; replaced with inline setPublishedDate helper
  • Removed now-unused resolveVersionPublishDate import from scanner.ts

Verification

  • TypeScript: no errors
  • Tests: 110/110 pass (lowest-safe-version, osv-cache, all detector tests)

@sonukapoor sonukapoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things to address before merging:

  1. The !packument early return in resolvePublishedFixVersion (before the first hunk in this file) omits publishedAt. Since the type marks it optional with ?, TypeScript will not flag this - but setPublishedDate in scanner.ts checks if (date === undefined) return and skips setting finding.fixVersionPublishedAt to null. The old attachFixVersionPublishDate explicitly set fixVersionPublishedAt = null when validation failed; this new path loses that guarantee. Adding publishedAt: null to the !packument return restores it.

  2. resolveVersionPublishDate in npm-registry.ts is now a dead export - the import was removed from scanner.ts but the function definition still exists. Worth deleting to keep the module surface clean.

Comment thread src/remediation/npm-registry.ts
Comment thread src/scanner.ts
…tions, remove redundant resolveVersionPublishDate call

resolvePublishedFixVersion and resolveLowestKnownNonVulnerableVersion both
already have the packument in scope. Adding publishedAt lets validateDirectFixTargets
skip the redundant resolveVersionPublishDate call (packument cache hit + time lookup).

- Extended PublishedFixVersionResolution with publishedAt?: string | null
- resolvePublishedFixVersion: added publishedAt to all 3 success return paths
- resolveLowestKnownNonVulnerableVersion: added publishedAt to success return
- Removed attachFixVersionPublishDate; replaced with inline setPublishedDate helper
- Removed unused resolveVersionPublishDate import from scanner.ts
… functions

- Extended mockPackument to accept optional time map
- Added publishedAt assertion to existing resolveLowestKnownNonVulnerableVersion test
- Added new resolvePublishedFixVersion describe with exact match publishedAt test
@luojiyin1987
luojiyin1987 force-pushed the perf/avoid-redundant-fix-version-lookup branch from 58ad247 to 39d6fa3 Compare June 23, 2026 00:34
@luojiyin1987
luojiyin1987 requested a review from sonukapoor June 23, 2026 00:56
@sonukapoor
sonukapoor merged commit 759ec48 into OWASP:main Jun 23, 2026
6 checks passed
@sonukapoor

Copy link
Copy Markdown
Collaborator

Merged — thank you @luojiyin1987!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: include publishedAt in fix version resolutions to avoid redundant resolveVersionPublishDate call

2 participants