mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-18 16:02:10 +00:00
perf: improve hub resource type pulling when using the cli (#5535)
This commit is contained in:
+13
-39
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user