Skip to content

Commit

Permalink
server: fix sortBy and sortOrder
Browse files Browse the repository at this point in the history
The commit fixes an issue when respecting `sortBy` and `sortOder`.
The proper ordering provided by the search-hits were not respected when
collecting them after being streamed.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Feb 23, 2024
1 parent 0ce7b7b commit 4c9adef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.eclipse.openvsx.cache.CacheService.*;
import static org.eclipse.openvsx.entities.FileResource.*;
Expand Down Expand Up @@ -709,9 +710,10 @@ public ResultJson deleteReview(String namespace, String extensionName) {
private List<Extension> getExtensions(SearchHits<ExtensionSearch> searchHits) {
var ids = searchHits.stream()
.map(searchHit -> searchHit.getContent().id)
.collect(Collectors.toSet());
.distinct()
.collect(Collectors.toList());

var extensions = new ArrayList<>(repositories.findExtensions(ids).toList());
var extensions = findExtensions(ids).collect(Collectors.toList());
var extensionIds = extensions.stream()
.map(Extension::getId)
.collect(Collectors.toSet());
Expand All @@ -737,6 +739,16 @@ private List<Extension> getExtensions(SearchHits<ExtensionSearch> searchHits) {
return extensions;
}

private Stream<Extension> findExtensions(Collection<Long> ids) {
var extById = new HashMap<Long, Extension>();
repositories.findExtensions(ids)
.forEach(ext -> extById.put(ext.getId(), ext));
return ids.stream()
.map(extById::get)
.filter(Objects::nonNull);
}


private List<SearchEntryJson> toSearchEntries(SearchHits<ExtensionSearch> searchHits, ISearchService.Options options) {
var serverUrl = UrlUtil.getBaseUrl();
var extensions = getExtensions(searchHits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ private List<Extension> mockSearch() {
var searchOptions = new ISearchService.Options("foo", null, null, 10, 0, "desc", "relevance", false);
Mockito.when(search.search(searchOptions))
.thenReturn(searchHits);
Mockito.when(repositories.findExtensions(Set.of(extension.getId())))
Mockito.when(repositories.findExtensions(List.of(extension.getId())))
.thenReturn(Streamable.of(extension));
return Arrays.asList(extension);
}
Expand Down

0 comments on commit 4c9adef

Please sign in to comment.