Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused queries #1102

Merged
merged 1 commit into from
Feb 4, 2025
Merged
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 @@ -21,8 +21,6 @@

public interface ExtensionRepository extends Repository<Extension, Long> {

Streamable<Extension> findByNameIgnoreCase(String name);

Streamable<Extension> findByNamespace(Namespace namespace);

Streamable<Extension> findByNamespaceAndActiveTrueOrderByNameAsc(Namespace namespace);
Expand All @@ -31,8 +29,6 @@ public interface ExtensionRepository extends Repository<Extension, Long> {

Extension findByNameIgnoreCaseAndNamespaceNameIgnoreCase(String name, String namespace);

Extension findByPublicId(String publicId);

Streamable<Extension> findByActiveTrue();

Streamable<Extension> findByIdIn(Collection<Long> extensionIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,6 @@ public Page<ExtensionVersion> findActiveVersions(QueryRequest request) {
return new PageImpl<>(content, PageRequest.of(request.offset() / request.size(), request.size()), total);
}

public ExtensionVersion findActiveByVersionAndExtensionNameAndNamespaceName(String version, String extensionName, String namespaceName) {
var query = findAllActive();
query.addConditions(
EXTENSION_VERSION.VERSION.eq(version),
EXTENSION.NAME.equalIgnoreCase(extensionName),
NAMESPACE.NAME.equalIgnoreCase(namespaceName)
);
query.addOrderBy(
EXTENSION_VERSION.UNIVERSAL_TARGET_PLATFORM.desc(),
EXTENSION_VERSION.TARGET_PLATFORM.asc()
);
query.addLimit(1);
var results = fetch(query);
return !results.isEmpty() ? results.get(0) : null;
}

public List<ExtensionVersion> findAllActiveByExtensionName(String targetPlatform, String extensionName) {
var query = findAllActive();
query.addConditions(EXTENSION.NAME.equalIgnoreCase(extensionName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public interface ExtensionVersionRepository extends Repository<ExtensionVersion,

Streamable<ExtensionVersion> findByExtensionAndActiveTrue(Extension extension);

Streamable<ExtensionVersion> findByVersionAndExtension(String version, Extension extension);

ExtensionVersion findByVersionAndTargetPlatformAndExtension(String version, String targetPlatform, Extension extension);

ExtensionVersion findByVersionAndTargetPlatformAndExtensionNameIgnoreCaseAndExtensionNamespaceNameIgnoreCase(String version, String targetPlatform, String extensionName, String namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ public FileResource findByType(String namespace, String extension, String target
return query.fetchOne(this::mapFindByQueryResult);
}

public FileResource findByTypeAndName(String namespace, String extension, String targetPlatform, String version, String type, String name) {
var onlyPreRelease = VersionAlias.PRE_RELEASE.equals(version);
var query = findByQuery(namespace, extension, version, targetPlatform, onlyPreRelease);
query.addConditions(
FILE_RESOURCE.TYPE.eq(type),
FILE_RESOURCE.NAME.equalIgnoreCase(name)
);
return query.fetchOne(this::mapFindByQueryResult);
}

private SelectQuery<Record> findByQuery(
String namespace,
String extension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ public Extension findExtension(String name, String namespace) {
return extensionRepo.findByNameIgnoreCaseAndNamespaceNameIgnoreCase(name, namespace);
}

public Extension findExtensionByPublicId(String publicId) {
return extensionRepo.findByPublicId(publicId);
}

public Streamable<Extension> findActiveExtensions(Namespace namespace) {
return extensionRepo.findByNamespaceAndActiveTrueOrderByNameAsc(namespace);
}
Expand All @@ -150,10 +146,6 @@ public Streamable<Extension> findExtensions(Namespace namespace) {
return extensionRepo.findByNamespace(namespace);
}

public Streamable<Extension> findExtensions(String name) {
return extensionRepo.findByNameIgnoreCase(name);
}

public Streamable<Extension> findAllActiveExtensions() {
return extensionRepo.findByActiveTrue();
}
Expand Down Expand Up @@ -182,10 +174,6 @@ public Streamable<ExtensionVersion> findVersions(Extension extension) {
return extensionVersionRepo.findByExtension(extension);
}

public Streamable<ExtensionVersion> findVersions(String version, Extension extension) {
return extensionVersionRepo.findByVersionAndExtension(version, extension);
}

public Streamable<ExtensionVersion> findActiveVersions(Extension extension) {
return extensionVersionRepo.findByExtensionAndActiveTrue(extension);
}
Expand Down Expand Up @@ -254,10 +242,6 @@ public FileResource findFileByName(String namespace, String extension, String ta
return fileResourceJooqRepo.findByName(namespace, extension, targetPlatform, version, name);
}

public FileResource findFileByTypeAndName(String namespace, String extension, String targetPlatform, String version, String type, String name) {
return fileResourceJooqRepo.findByTypeAndName(namespace, extension, targetPlatform, version, type, name);
}

public Streamable<FileResource> findDownloadsByStorageTypeAndName(String storageType, Collection<String> names) {
return fileResourceRepo.findByTypeAndStorageTypeAndNameIgnoreCaseIn(DOWNLOAD, storageType, names);
}
Expand Down Expand Up @@ -398,10 +382,6 @@ public List<ExtensionVersion> findActiveExtensionVersions(Collection<Long> exten
return extensionVersionJooqRepo.findAllActiveByExtensionIdAndTargetPlatform(extensionIds, targetPlatform);
}

public ExtensionVersion findActiveExtensionVersion(String version, String extensionName, String namespaceName) {
return extensionVersionJooqRepo.findActiveByVersionAndExtensionNameAndNamespaceName(version, extensionName, namespaceName);
}

public List<FileResource> findFileResourcesByExtensionVersionIdAndType(Collection<Long> extensionVersionIds, Collection<String> types) {
return fileResourceJooqRepo.findAll(extensionVersionIds, types);
}
Expand Down Expand Up @@ -462,10 +442,6 @@ public Streamable<ExtensionVersion> findTargetPlatformVersions(String version, S
return extensionVersionRepo.findByVersionAndExtensionNameIgnoreCaseAndExtensionNamespaceNameIgnoreCase(version, extensionName, namespaceName);
}

public void deleteFileResources(ExtensionVersion extVersion, String type) {
fileResourceRepo.deleteByExtensionAndType(extVersion, type);
}

public int countVersions(Extension extension) {
return extensionVersionRepo.countByExtension(extension);
}
Expand Down
6 changes: 0 additions & 6 deletions server/src/test/java/org/eclipse/openvsx/RegistryAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2017,10 +2017,6 @@ private ExtensionVersion mockExtension(String targetPlatform, boolean withSignat
.thenReturn(0L);
Mockito.when(repositories.findNamespace("foo"))
.thenReturn(namespace);
Mockito.when(repositories.findExtensions("bar"))
.thenReturn(Streamable.of(extension));
Mockito.when(repositories.findExtensionByPublicId("5678"))
.thenReturn(extension);

var download = new FileResource();
download.setExtension(extVersion);
Expand Down Expand Up @@ -2242,8 +2238,6 @@ private void mockForPublish(String mode) {
.thenReturn(Streamable.empty());
Mockito.when(repositories.findFilesByType(anyCollection(), anyCollection()))
.thenReturn(Collections.emptyList());
Mockito.when(repositories.findVersions(eq("1.0.0"), any(Extension.class)))
.thenReturn(Streamable.empty());
if (mode.equals("owner")) {
var ownerMem = new NamespaceMembership();
ownerMem.setUser(token.getUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,6 @@ private ExtensionVersion mockExtensionVersion(String targetPlatform) throws Json
extVersion.setEngines(Lists.newArrayList("vscode@^1.31.0"));
extVersion.setDependencies(Lists.newArrayList());
extVersion.setBundledExtensions(Lists.newArrayList());
Mockito.when(repositories.findExtensionByPublicId("test-1"))
.thenReturn(extension);
Mockito.when(repositories.findExtension("vscode-yaml", "redhat"))
.thenReturn(extension);
Mockito.when(repositories.findVersion("0.5.2", targetPlatform, "vscode-yaml", "redhat"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ void testExecuteQueries() {
() -> repositories.findDownloadsByStorageTypeAndName("storageType", STRING_LIST),
() -> repositories.findExtension("name", namespace),
() -> repositories.findExtension("name", "namespace"),
() -> repositories.findExtensionByPublicId("publicId"),
() -> repositories.findExtensions(namespace),
() -> repositories.findExtensions("name"),
() -> repositories.findFileByType(extVersion, "type"),
() -> repositories.findFiles(extVersion),
() -> repositories.findFilesByStorageType("storageType"),
Expand All @@ -128,7 +126,6 @@ void testExecuteQueries() {
() -> repositories.findVersion("version", "targetPlatform", extension),
() -> repositories.findVersion("version", "targetPlatform", "extensionName", "namespace"),
() -> repositories.findVersions(extension),
() -> repositories.findVersions("version", extension),
() -> repositories.findVersionsByAccessToken(personalAccessToken, true),
() -> repositories.getMaxExtensionDownloadCount(),
() -> repositories.getOldestExtensionTimestamp(),
Expand All @@ -137,7 +134,6 @@ void testExecuteQueries() {
() -> repositories.findFilesByType(List.of(extVersion), STRING_LIST),
() -> repositories.countVersions(extension),
() -> repositories.topMostDownloadedExtensions(1),
() -> repositories.deleteFileResources(extVersion, "download"),
() -> repositories.countActiveAccessTokens(userData),
() -> repositories.findNotMigratedPreReleases(),
() -> repositories.findNotMigratedRenamedDownloads(),
Expand Down Expand Up @@ -202,10 +198,8 @@ void testExecuteQueries() {
() -> repositories.deleteFiles(extVersion),
() -> repositories.findExtensionTargetPlatforms(extension),
() -> repositories.deactivateKeyPairs(),
() -> repositories.findActiveExtensionVersion("version", "extensionName", "namespaceName"),
() -> repositories.findActiveAccessTokens(userData),
() -> repositories.isAdminToken("tokenValue"),
() -> repositories.findFileByTypeAndName("namespaceName", "extensionName", "targetPlatform", "version", "type", "name"),
() -> repositories.findLatestVersions(List.of(1L)),
() -> repositories.hasSameVersion(extVersion),
() -> repositories.hasActiveReview(extension, userData),
Expand Down