perf: improve hub resource type pulling when using the cli (#5535)

This commit is contained in:
HugoCasa
2025-03-28 17:24:24 +01:00
committed by GitHub
parent c020af5a98
commit dd488a2bdb
+13 -39
View File
@@ -9,6 +9,14 @@ import { deepEqual } from "./utils.ts";
const DEFAULT_HUB_BASE_URL = "https://hub.windmill.dev";
interface HubResourceType {
id: number;
name: string;
schema: string;
app: string;
description: string;
}
export async function pull(opts: GlobalOptions) {
const workspace = await resolveWorkspace(opts);
@@ -39,50 +47,16 @@ export async function pull(opts: GlobalOptions) {
headers["X-uid"] = uid;
}
let preList = await fetch(hubBaseUrl + "/resource_types/list", {
let list = await fetch(hubBaseUrl + "/resource_types/list", {
headers,
}).then((r) => r.json() as Promise<{ id: number; name: string }[]>);
}).then((r) => r.json() as Promise<HubResourceType[]>);
if (preList && preList.length === 0 && hubBaseUrl !== DEFAULT_HUB_BASE_URL) {
preList = await fetch(DEFAULT_HUB_BASE_URL + "/resource_types/list", {
if (list && list.length === 0 && hubBaseUrl !== DEFAULT_HUB_BASE_URL) {
list = await fetch(DEFAULT_HUB_BASE_URL + "/resource_types/list", {
headers,
}).then((r) => r.json() as Promise<{ id: number; name: string }[]>);
}).then((r) => r.json() as Promise<HubResourceType[]>);
}
let list: {
id: number;
name: string;
schema: string;
approved: boolean;
app: string;
description: string;
created_by: string;
created_at: Date;
comments: never[];
}[] = await Promise.all(
preList.map((x) =>
fetch(hubBaseUrl + "/resource_types/" + x.id + "/" + x.name, {
headers: {
Accept: "application/json",
},
})
)
)
.then((x) =>
x.map((x) =>
x.json().catch((e) => {
log.info(e);
return undefined;
})
)
)
.then((x) => Promise.all(x))
.then((x) =>
(x as { resource_type: any }[])
.filter((x) => x)
.map((x) => x.resource_type)
);
const resourceTypes = await wmill.listResourceType({
workspace: workspace.workspaceId,
});