Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,18 @@ public ExtensionQueryResult extensionQuery(ExtensionQueryParam param, int defaul
// see https://github.com/eclipse/openvsx/issues/1394
var extensionsMap = extensionsList.stream()
.collect(Collectors.toMap(Extension::getId, Function.identity(), (a, b) -> a));
List<ExtensionVersion> allActiveExtensionVersions = repositories
.findActiveExtensionVersions(extensionsMap.keySet(), targetPlatform, maxPreReleaseVersions);

// The full active version list (all pre-releases included, unless capped) is only needed to populate
// the response's per-extension version list, which itself is only included for these flags. Skipping
// the fetch otherwise avoids pulling an extension's entire (potentially unbounded) version history
// just to compute "latest", which repositories.findLatestVersions below does directly in the database.
var needsVersionList = test(flags, FLAG_INCLUDE_LATEST_VERSION_ONLY)
|| test(flags, FLAG_INCLUDE_VERSIONS)
|| test(flags, FLAG_INCLUDE_VERSION_PROPERTIES);
List<ExtensionVersion> allActiveExtensionVersions = needsVersionList
? repositories
.findActiveExtensionVersions(extensionsMap.keySet(), targetPlatform, maxPreReleaseVersions)
: Collections.emptyList();

List<ExtensionVersion> extensionVersions;
if (test(flags, FLAG_INCLUDE_LATEST_VERSION_ONLY)) {
Expand Down Expand Up @@ -262,11 +272,7 @@ public ExtensionQueryResult extensionQuery(ExtensionQueryParam param, int defaul
fileResources = Collections.emptyMap();
}

var latestVersions = allActiveExtensionVersions.stream()
.collect(Collectors.groupingBy(ev -> ev.getExtension().getId()))
.values()
.stream()
.map(list -> versions.getLatest(list, false))
var latestVersions = repositories.findLatestVersions(extensionsMap.keySet(), targetPlatform).stream()
.collect(Collectors.toMap(ev -> ev.getExtension().getId(), ev -> ev));

var extensionQueryResults = new ArrayList<ExtensionQueryResult.Extension>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,11 @@ public Map<Long, Boolean> findLatestIsPreview(Collection<Long> extensionIds) {
}

public List<ExtensionVersion> findLatest(Collection<Long> extensionIds) {
var latestQuery = findLatestQuery(null, false, true);
return findLatest(extensionIds, null);
}

public List<ExtensionVersion> findLatest(Collection<Long> extensionIds, String targetPlatform) {
var latestQuery = findLatestQuery(targetPlatform, false, true);
latestQuery.addSelect(
EXTENSION_VERSION.ID,
EXTENSION_VERSION.VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,10 @@ public List<ExtensionVersion> findLatestVersions(Collection<Long> extensionIds)
return extensionVersionJooqRepo.findLatest(extensionIds);
}

public List<ExtensionVersion> findLatestVersions(Collection<Long> extensionIds, String targetPlatform) {
return extensionVersionJooqRepo.findLatest(extensionIds, targetPlatform);
}

public Map<Long, Boolean> findLatestVersionsIsPreview(Collection<Long> extensionIds) {
return extensionVersionJooqRepo.findLatestIsPreview(extensionIds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void testDuplicateExtensionsInSearch() {
.thenReturn(List.of(extension, extension));
Mockito.when(repositories.findActiveExtensionVersions(any(), any(), anyInt()))
.thenReturn(List.of(extensionVersion));
Mockito.when(repositories.findLatestVersions(any(), any())).thenReturn(List.of(extensionVersion));
Mockito.when(versions.getLatest(anyList(), anyBoolean())).thenReturn(extensionVersion);

var result = vsCodeService.extensionQuery(param, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,11 @@ private void mockExtensionVersions(
anyInt()))
.thenReturn(extVersions);

var latest = extVersions.stream().min(ExtensionVersion.SORT_COMPARATOR).orElse(null);
Mockito
.when(repositories.findLatestVersions(eq(Set.of(extension.getId())), eq(queryTargetPlatform)))
.thenReturn(latest != null ? List.of(latest) : Collections.emptyList());

mockFileResources(extVersions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ void testExecuteQueries() {
() -> repositories.findActivePersonalAccessTokensAndType(userData, PersonalAccessTokenType.LLT),
() -> repositories.findAllPersonalAccessTokensByVersion(0),
() -> repositories.findLatestVersions(List.of(1L)),
() -> repositories.findLatestVersions(List.of(1L), "targetPlatform"),
() -> repositories.hasSameVersion(extVersion),
() -> repositories.hasActiveReview(extension, userData),
() -> repositories.findLatestVersionsIsPreview(List.of(1L)),
Expand Down