mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-27 06:01:08 +08:00
More work towards preloading dependencies
This commit is contained in:
parent
0b799b74eb
commit
63f930dffc
@ -25,6 +25,7 @@ import { remove } from "lodash-es";
|
||||
import { useBackendDataStore } from "~/store/backendData";
|
||||
import DependencyTable from "~/components/projects/DependencyTable.vue";
|
||||
import InputTag from "~/components/ui/InputTag.vue";
|
||||
import {LastDependencies} from "hangar-api";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@ -87,6 +88,31 @@ const platformVersionRules = computed(() => {
|
||||
return !pendingVersion.value?.isFile ? [] : [(v: string[]) => !!v.length || "Error"];
|
||||
});
|
||||
|
||||
async function preload() {
|
||||
if (!pendingVersion.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const platform in pendingVersion.value.platformDependencies) {
|
||||
// Get last platform and plugin dependency data for the last version of the same channel/any other channel if not found
|
||||
useInternalApi<LastDependencies>(`versions/version/${props.project.namespace.owner}/${props.project.namespace.slug}/lastdependencies`, true)
|
||||
.then(v => {
|
||||
if (!v) {
|
||||
return
|
||||
}
|
||||
|
||||
for (const platformVersion of v.platformDependencies) {
|
||||
//TODO list of strings (e.g. "1.18", "1.19")
|
||||
}
|
||||
for (const pluginDependency of v.pluginDependencies) {
|
||||
//TODO
|
||||
}
|
||||
}).catch<any>((e) =>
|
||||
handleRequestError(e, ctx, i18n)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createPendingVersion() {
|
||||
loading.create = true;
|
||||
const data: FormData = new FormData();
|
||||
|
5
frontend/src/types/api/versions.d.ts
vendored
5
frontend/src/types/api/versions.d.ts
vendored
@ -8,6 +8,11 @@ declare module "hangar-api" {
|
||||
externalUrl: string | null;
|
||||
}
|
||||
|
||||
interface LastDependencies {
|
||||
pluginDependencies: PluginDependency[];
|
||||
platformDependencies: string[];
|
||||
}
|
||||
|
||||
interface VersionStats {
|
||||
downloads: number;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package io.papermc.hangar.controller.internal;
|
||||
|
||||
import io.papermc.hangar.HangarComponent;
|
||||
import io.papermc.hangar.exceptions.HangarApiException;
|
||||
import io.papermc.hangar.model.api.project.version.PluginDependency;
|
||||
import io.papermc.hangar.model.common.NamedPermission;
|
||||
import io.papermc.hangar.model.common.PermissionType;
|
||||
import io.papermc.hangar.model.common.Platform;
|
||||
@ -15,6 +14,7 @@ import io.papermc.hangar.model.internal.logs.LogAction;
|
||||
import io.papermc.hangar.model.internal.logs.contexts.VersionContext;
|
||||
import io.papermc.hangar.model.internal.versions.HangarVersion;
|
||||
import io.papermc.hangar.model.internal.versions.PendingVersion;
|
||||
import io.papermc.hangar.model.internal.versions.LastDependencies;
|
||||
import io.papermc.hangar.security.annotations.permission.PermissionRequired;
|
||||
import io.papermc.hangar.security.annotations.ratelimit.RateLimit;
|
||||
import io.papermc.hangar.security.annotations.unlocked.Unlocked;
|
||||
@ -201,7 +201,7 @@ public class VersionController extends HangarComponent {
|
||||
@VisibilityRequired(type = Type.PROJECT, args = "{#author, #slug}")
|
||||
@RateLimit(overdraft = 5, refillTokens = 2, refillSeconds = 10)
|
||||
@GetMapping(path = "/version/{author}/{slug}/lastdependencies")
|
||||
public ResponseEntity<List<PluginDependency>> getLastVersionDependencies(@PathVariable String author, @PathVariable String slug, @RequestParam(required = false) String channel, @RequestParam String platform) {
|
||||
public ResponseEntity<LastDependencies> getLastVersionDependencies(@PathVariable String author, @PathVariable String slug, @RequestParam(required = false) String channel, @RequestParam String platform) {
|
||||
return ResponseEntity.ok(versionService.getLastVersionDependencies(author, slug, channel, platform));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.papermc.hangar.model.internal.versions;
|
||||
|
||||
import io.papermc.hangar.model.api.project.version.PluginDependency;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LastDependencies {
|
||||
public static final LastDependencies EMPTY = new LastDependencies(List.of(), List.of());
|
||||
private final List<String> platformDependencies;
|
||||
private final List<PluginDependency> pluginDependencies;
|
||||
|
||||
public LastDependencies(List<String> platformDependencies, List<PluginDependency> pluginDependencies) {
|
||||
this.platformDependencies = platformDependencies;
|
||||
this.pluginDependencies = pluginDependencies;
|
||||
}
|
||||
|
||||
public List<String> getPlatformDependencies() {
|
||||
return platformDependencies;
|
||||
}
|
||||
|
||||
public List<PluginDependency> getPluginDependencies() {
|
||||
return pluginDependencies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LastDependencies{" +
|
||||
"platformDependencies=" + platformDependencies +
|
||||
", pluginDependencies=" + pluginDependencies +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import io.papermc.hangar.db.dao.internal.table.versions.ProjectVersionsDAO;
|
||||
import io.papermc.hangar.db.dao.internal.versions.HangarVersionsDAO;
|
||||
import io.papermc.hangar.db.dao.v1.VersionsApiDAO;
|
||||
import io.papermc.hangar.exceptions.HangarApiException;
|
||||
import io.papermc.hangar.model.api.project.version.PluginDependency;
|
||||
import io.papermc.hangar.model.api.requests.RequestPagination;
|
||||
import io.papermc.hangar.model.common.Permission;
|
||||
import io.papermc.hangar.model.common.Platform;
|
||||
@ -17,6 +16,7 @@ import io.papermc.hangar.model.db.versions.ProjectVersionTable;
|
||||
import io.papermc.hangar.model.internal.logs.LogAction;
|
||||
import io.papermc.hangar.model.internal.logs.contexts.VersionContext;
|
||||
import io.papermc.hangar.model.internal.versions.HangarVersion;
|
||||
import io.papermc.hangar.model.internal.versions.LastDependencies;
|
||||
import io.papermc.hangar.service.internal.uploads.ProjectFiles;
|
||||
import io.papermc.hangar.service.internal.visibility.ProjectVersionVisibilityService;
|
||||
import io.papermc.hangar.service.internal.visibility.ProjectVisibilityService;
|
||||
@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@ -88,7 +89,7 @@ public class VersionService extends HangarComponent {
|
||||
return versions.stream().map(v -> versionDependencyService.addDependenciesAndTags(v.getId(), v)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<PluginDependency> getLastVersionDependencies(String author, String slug, @Nullable String channel, String platformName) {
|
||||
public LastDependencies getLastVersionDependencies(String author, String slug, @Nullable String channel, String platformName) {
|
||||
Platform platform = Platform.valueOf(platformName.toUpperCase());
|
||||
|
||||
RequestPagination pagination = new RequestPagination(1L, 0L);
|
||||
@ -100,11 +101,15 @@ public class VersionService extends HangarComponent {
|
||||
|
||||
Long versionId = versionsApiDAO.getVersions(author, slug, false, getHangarUserId(), pagination).entrySet().stream().map(Map.Entry::getKey).findAny().orElse(null);
|
||||
if (versionId != null) {
|
||||
return new ArrayList<>(versionsApiDAO.getPluginDependencies(versionId, platform));
|
||||
SortedSet<String> platformDependency = versionsApiDAO.getPlatformDependencies(versionId).get(platform);
|
||||
if (platformDependency != null) {
|
||||
return new LastDependencies(new ArrayList<>(platformDependency), new ArrayList<>(versionsApiDAO.getPluginDependencies(versionId, platform)));
|
||||
}
|
||||
return LastDependencies.EMPTY;
|
||||
}
|
||||
|
||||
// Try again with any channel, else empty
|
||||
return channel != null ? getLastVersionDependencies(author, slug, null, platformName) : List.of();
|
||||
return channel != null ? getLastVersionDependencies(author, slug, null, platformName) : LastDependencies.EMPTY;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
Loading…
Reference in New Issue
Block a user