Skip to content

fix: cap pre-release versions returned by extensionQuery - #2062

Merged
netomi merged 3 commits into
mainfrom
fix/extensionquery-prerelease-version-cap
Aug 9, 2026
Merged

netomi merged 3 commits into
mainfrom
fix/extensionquery-prerelease-version-cap

Conversation

@netomi

@netomi netomi commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What

extensionQuery (/vscode/gallery/extensionquery) fetches every active version of every requested extension when FLAG_INCLUDE_VERSIONS or FLAG_INCLUDE_VERSION_PROPERTIES is set. For an extension whose pre-release channel publishes one build per commit, that history can grow into the thousands, making the query and the response needlessly expensive.

Regular releases are left completely untouched. Active pre-release versions are now capped to the most recent N per extension (combined across all of its target platforms), ranked by the same semver-based ordering ExtensionVersion.SORT_COMPARATOR uses for "latest" - so the true latest pre-release (rank #1) can never be dropped by the cap, and downstream "latest version" computations stay correct.

How

The cap is a plain method parameter threaded through:

LocalVSCodeService -> RepositoryService.findActiveExtensionVersions -> ExtensionVersionJooqRepository.findAllActiveByExtensionIdAndTargetPlatform

configured on LocalVSCodeService via ovsx.extension-query.max-pre-release-versions (default 100). A negative value (e.g. -1) disables the cap entirely, matching the "negative means unlimited" convention already used for ovsx.data.mirror.requests-per-second.

Implementation detail: the SQL adds a correlated-subquery condition (EXTENSION_VERSION.PRE_RELEASE.isFalse().or(isAmongLatestPreReleases(limit))) rather than a window-function/derived-table rewrite, since the existing flat query's generic toExtensionVersion row mapper can't safely be reused once wrapped in a derived table (duplicate NAMESPACE.ID/EXTENSION.ID/EXTENSION_VERSION.ID column names collide once re-selected).

Testing

ExtensionVersionJooqRepositoryTest gains coverage for:

  • capping pre-releases while leaving all stable releases untouched
  • capping across an extension's target platforms combined, not per platform
  • the target-platform filter being applied after the cross-platform cap (so a platform-scoped request can see fewer versions than exist for that platform)
  • honouring a caller-supplied limit rather than a value fixed in the repository
  • a negative limit disabling the cap entirely

Existing call sites/mocks (LocalVSCodeServiceTest, VSCodeAPITest, RegistryAPITest, RepositoryServiceSmokeTest) updated for the new parameter.

extensionQuery (vscode/gallery/extensionquery) fetches every active
version of every requested extension when FLAG_INCLUDE_VERSIONS or
FLAG_INCLUDE_VERSION_PROPERTIES is set. For an extension whose
pre-release channel publishes one build per commit, that history can
grow into the thousands, making the query and response needlessly
expensive.

Regular releases are left untouched, but active pre-release versions
are now capped to the most recent N per extension (combined across
all of its target platforms), ranked by the same semver-based
ordering ExtensionVersion.SORT_COMPARATOR uses for "latest" - so the
true latest pre-release (rank #1) is never dropped by the cap.

The cap is a plain method parameter threaded through
LocalVSCodeService -> RepositoryService -> ExtensionVersionJooqRepository,
configured via ovsx.extension-query.max-pre-release-versions (default
100). A negative value (e.g. -1) disables the cap entirely, matching
the "negative means unlimited" convention already used for
ovsx.data.mirror.requests-per-second.

Adds coverage in ExtensionVersionJooqRepositoryTest for: capping
while leaving stable releases untouched, capping across target
platforms combined rather than per platform, the target-platform
filter being applied after the cap, honouring a caller-supplied
limit, and disabling the cap with a negative value.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a configurable cap on how many active pre-release channel versions are returned by the VS Code extensionQuery path, to prevent queries/responses from growing unbounded when pre-release channels publish very frequently, while leaving stable releases unaffected.

Changes:

  • Thread a maxPreReleaseVersions parameter through LocalVSCodeService -> RepositoryService -> ExtensionVersionJooqRepository.
  • Implement repository-side filtering to limit active pre-release versions per extension (cross-platform combined), with a negative value disabling the cap.
  • Add/adjust tests and mocks to cover the new behavior and updated method signature.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/src/main/java/org/eclipse/openvsx/adapter/LocalVSCodeService.java Adds configurable ovsx.extension-query.max-pre-release-versions and passes it into repository query.
server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java Extends findActiveExtensionVersions to accept maxPreReleaseVersions.
server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java Adds SQL-side pre-release capping logic.
server/src/test/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepositoryTest.java Adds coverage for pre-release capping semantics (stable untouched, cross-platform cap, negative disables).
server/src/test/java/org/eclipse/openvsx/repositories/RepositoryServiceSmokeTest.java Updates smoke test call site for new method signature.
server/src/test/java/org/eclipse/openvsx/adapter/LocalVSCodeServiceTest.java Updates mocks for new repository method signature.
server/src/test/java/org/eclipse/openvsx/adapter/VSCodeAPITest.java Updates mocks for new repository method signature.
server/src/test/java/org/eclipse/openvsx/RegistryAPITest.java Updates mocks for new repository method signature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

netomi and others added 2 commits August 9, 2026 14:10
Addresses a review comment on this PR: isAmongLatestPreReleases
ranked pre-releases by (semver_major, semver_minor, semver_patch)
alone. Two rows tied on that triple - the normal case, not an edge
case, since the same version published across several target
platforms shares one (major, minor, patch) by construction, and a
pre-release channel that republishes without bumping semver ties too
- neither outranks the other, so neither counts against the cap.
Unbounded ties meant the cap could fail to cap at all for exactly the
"one build per commit" pre-release channel this PR targets.

Fall back to timestamp, matching ExtensionVersion.SORT_COMPARATOR and
every DB sort index in this class, which already resolve same-semver
ties that way. Add id as a final tiebreaker so the comparison is a
strict total order, guaranteeing the cap keeps exactly
min(limit, total) rows rather than "at least".

Adds a regression test with 105 pre-release versions sharing one
version string (only target platform and timestamp differ) that
fails on the prior comparison (105 returned, uncapped) and passes
with the fix (capped to 100, most recent one kept).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Make the pre-release cap opt-in rather than on-by-default: -1
(disabled) preserves the exact pre-existing, uncapped behaviour out
of the box. Operators who want the cap set
ovsx.extension-query.max-pre-release-versions explicitly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (2)

server/src/main/java/org/eclipse/openvsx/adapter/LocalVSCodeService.java:99

  • The PR description says ovsx.extension-query.max-pre-release-versions defaults to 100, but the code currently defaults to -1 (unlimited). This is a behavioral mismatch: with -1 the cap is disabled unless operators opt in, which contradicts the stated default and the PR’s stated purpose of reducing expensive queries/responses by default.
    // fetches per extensionQuery request; regular releases are never capped. A negative value
    // (e.g. the -1 default) disables the cap entirely, preserving the pre-existing unbounded
    // behaviour unless an operator opts into capping.
    @Value("${ovsx.extension-query.max-pre-release-versions:-1}")
    int maxPreReleaseVersions;

server/src/test/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepositoryTest.java:222

  • This comment says the cross-platform cap is applied before the “win32-x64 filter below”, but the test actually requests linux-x64 only. The wording is misleading when reading the test intent.
        // 99 higher-semver win32 pre-releases crowd out all but the newest of the 2 linux
        // pre-releases from the cross-platform top-100 cap, before the win32-x64 filter below is
        // even applied - so requesting linux-x64 only can see fewer than 100 versions even though
        // more than 100 exist for the extension overall.

@netomi
netomi merged commit 5ecf24b into main Aug 9, 2026
5 checks passed
@netomi
netomi deleted the fix/extensionquery-prerelease-version-cap branch August 9, 2026 14:30
netomi added a commit that referenced this pull request Aug 31, 2026
* Rework prerelease limit SQL

* Update partition

* Improve it

* Fixes

* Fix ranking

* One more down

* Fix bug re type and ranking

* fix: SQL error and NULLS ordering in prerelease-capped version query

findAllActiveByExtensionIdAndTargetPlatform appended the target
platform condition via field(name("extension_version_target_platform"))
unconditionally, referencing a select-list alias from the WHERE clause
of the same query. That is only valid once the query has been wrapped
in the ranked_extension_version CTE (maxPreReleaseVersions >= 0); with
the cap disabled (the default, -1) there is no CTE, and Postgres
rejects the query outright once a target platform is supplied - which
VS Code's extensionQuery always does. Now the capped branch keeps
using the typed CTE field lookup, and the uncapped branch applies the
condition directly against the real EXTENSION_VERSION.TARGET_PLATFORM
column of its own (non-wrapped) query.

Also added nullsLast() to the semver ordering the "rank" window
function uses: Postgres defaults DESC to NULLS FIRST, so a legacy
version row with no parsed semver would otherwise outrank every real
semver version and could push the true latest pre-release out of the
capped result set, contradicting this method's own "rank #1 is never
dropped" guarantee.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* test: add performance comparison against the old correlated-subquery ranking

Ports the pre-rework findAllActiveByExtensionIdAndTargetPlatform (a
correlated COUNT(*) subquery per pre-release row, O(k^2) for an
extension with k pre-releases) as a test-local helper, purely so it
has something to compare the reworked denseRank() window-function
query against - the original method itself is gone.

Measured against a real Postgres instance with 3000 pre-release
versions on one extension (the volume this method's own doc comment
is written around): old ~3023ms, new ~56ms, roughly a 54x speedup.
The assertion allows a generous margin (3x + 500ms) rather than
pinning an exact ratio, since this is real wall-clock timing against
a container DB, not a controlled microbenchmark - the point is to
catch a severe regression, not chase a precise number.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix: TableFieldMapper's remap guard was inverted, never actually remapping

TableFieldMapper.map(...) only called table.field(field) - the actual
remap onto the derived table - when the field's owning table already
equaled table, which never happens for a static-table field constant
(EXTENSION_VERSION.ID's table is always the static EXTENSION_VERSION
table, never a derived "latest" table). So it always returned the
field unchanged, regardless of intent: dead code, masked only because
Record.get(...) happens to resolve those raw fields against the
correct row column anyway via its own field-matching fallback.

Flipped the condition so it actually remaps whenever the field
belongs to a different table (the case that matters), falling back
to the unchanged field when table.field(field) itself returns null -
which happens for a field with no lineage relationship to table at
all, e.g. NAMESPACE.ID/EXTENSION.ID read through the same mapper
instance alongside genuine EXTENSION_VERSION.* fields in
toExtensionVersionCommon. Confirmed the fix doesn't regress: it
compiled and passed 1064/1064 tests, including a new regression test
that would fail if the wrong same-named "id" column were ever read.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* test: also compare the rework against the pre-limiting baseline

Extends the performance test with a third baseline: a port of
findAllActiveByExtensionIdAndTargetPlatform as it existed before
#2062 introduced pre-release limiting at all - a bare filtered
SELECT with no ranking whatsoever. The reworked query computes its
denseRank() window function unconditionally, even on the uncapped
(default, max-pre-release-versions=-1) path where nothing reads it,
so this checks that overhead isn't a meaningful regression against
the simplest query that could possibly answer the same question -
the path every caller takes unless an operator opts into the cap.

Measured (3000 pre-release versions, same run):
- old capped (correlated subquery):        1620ms
- new capped (window function):              20ms
- no-limit-at-all baseline (pre-#2062):        9ms
- new uncapped (unused window function):    132ms

The capped comparison remains a clear win (~80x here). The uncapped
comparison shows the "computed even when unused" window function is
a real, measurable overhead (~14x the baseline in this run) - still
comfortably fast in absolute terms and within the assertion's
generous margin, but a genuine cost worth having on record rather
than only asserted away.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* perf: fix the uncapped-path regression found by the new perf test

Two changes to close the ~14x gap the extended performance test
found between the uncapped path and the pre-limiting baseline:

1. Skip building the denseRank() window function entirely when the
   cap is disabled (the default), instead of computing it and simply
   not reading the result. This also let the uncapped path drop the
   aliasing/CTE machinery altogether: it now selects the same plain,
   unaliased columns the pre-#2062 method did and maps them via the
   existing toExtensionVersion/IdentityFieldMapper path, rather than
   sharing one aliased field list with the capped path and needing
   RankedFieldMapper to translate between them. The aliasing exists
   only because the capped path's CTE needs every column uniquely
   named to reference by string (NAMESPACE.ID/EXTENSION.ID/
   EXTENSION_VERSION.ID would otherwise all render as "id") - the
   uncapped path never had that requirement.

2. This isolated the real dominant cost, which turned out to be
   RankedFieldMapper itself (still needed for the capped path): it
   resolved each mapped column by constructing a brand-new, unrelated
   Field object and handing that to row.get(...), which forces jOOQ
   into a slow fallback lookup. Resolving through the row's own
   name-indexed field(String) lookup instead - the row's native,
   fast path - fixed it. (The derived name string, a pure function of
   the static field, is still cached; only the per-row Field
   reconstruction was the problem.)

Measured (3000 pre-release versions, same run):
  before:                      no-limit baseline ~19ms, new uncapped ~127ms (~7x)
  after denseRank() skip:      no-limit baseline ~19ms, new uncapped ~132ms (no change - not the bottleneck)
  after RankedFieldMapper fix: no-limit baseline ~19ms, new uncapped ~25-47ms
  after the field-list split:  no-limit baseline ~32ms, new uncapped ~39ms

toExtensionVersion (used by the uncapped path) is now package-private
so the performance test can build a fair, equally-mapped baseline
instead of a mapping-free one that would have understated the actual
per-row cost both approaches pay.

Full suite: 1064/1064 passing.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Thomas Neidhart <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

2 participants