mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 20:06:10 +00:00
perf(mobile): read new-workspace host labels through the stored host-list query
This commit is contained in:
@@ -20,7 +20,7 @@ export function NewWorkspacePageScreen() {
|
||||
const { hostCapabilities } = useHostProtocolGates()
|
||||
const connected = connState === 'connected'
|
||||
const worktrees = useHostWorktreeRows(client, connected, hostId)
|
||||
const hostLabelById = useHostLabelById(client, connected)
|
||||
const hostLabelById = useHostLabelById(client, connected, hostId)
|
||||
const worktreePaths = useMemo(() => worktrees.map((worktree) => worktree.path), [worktrees])
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,32 +1,26 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import type { ExecutionHostId } from '../../../src/shared/execution-host'
|
||||
import { readHostSshTargetLabels } from '../host-screen/host-ssh-target-labels-read'
|
||||
import {
|
||||
HOST_LIST_TARGET,
|
||||
hostRepoLabelsQuery,
|
||||
NO_HOST_LIST_INPUT
|
||||
} from '../host-screen/host-list-queries'
|
||||
import { useHostQuery } from '../query/host-query'
|
||||
import type { RpcClient } from '../transport/rpc/rpc-client-contract'
|
||||
|
||||
const NO_HOST_LABELS: ReadonlyMap<ExecutionHostId, string> = new Map()
|
||||
|
||||
// The host list's labels: the drawer shows the stored ones at once and the read refreshes them.
|
||||
export function useHostLabelById(
|
||||
client: RpcClient | null,
|
||||
connected: boolean
|
||||
connected: boolean,
|
||||
hostId: string
|
||||
): ReadonlyMap<ExecutionHostId, string> {
|
||||
const [labels, setLabels] = useState(NO_HOST_LABELS)
|
||||
|
||||
useEffect(() => {
|
||||
if (!client || !connected) {
|
||||
return
|
||||
}
|
||||
let live = true
|
||||
readHostSshTargetLabels(client)
|
||||
.then(({ hostLabelById }) => {
|
||||
if (live) {
|
||||
setLabels(hostLabelById)
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
return () => {
|
||||
live = false
|
||||
}
|
||||
}, [client, connected])
|
||||
|
||||
return labels
|
||||
const { data } = useHostQuery(
|
||||
hostRepoLabelsQuery,
|
||||
{ hostId, client: connected ? client : null },
|
||||
HOST_LIST_TARGET,
|
||||
NO_HOST_LIST_INPUT
|
||||
)
|
||||
return useMemo(() => (data ? new Map(data.hostLabels) : NO_HOST_LABELS), [data])
|
||||
}
|
||||
|
||||
@@ -40,6 +40,16 @@ export function firstPaintQueryKeys(hostId: string, route: URL): PersistedHostQu
|
||||
if (screen === 'tasks') {
|
||||
return firstPaintTaskKeys(hostId)
|
||||
}
|
||||
if (screen === 'new-workspace') {
|
||||
// The drawer's existing-workspace check and host labels.
|
||||
return [
|
||||
persistedHostQueryKey(hostWorktreeCatalogQuery, hostWorktreeCatalogKey(hostId)),
|
||||
persistedHostQueryKey(
|
||||
hostRepoLabelsQuery,
|
||||
hostQueryKey(hostId, hostRepoLabelsQuery.family, HOST_LIST_TARGET, NO_HOST_LIST_INPUT)
|
||||
)
|
||||
].filter((key) => key !== null)
|
||||
}
|
||||
const keys =
|
||||
screen === undefined
|
||||
? [
|
||||
|
||||
Reference in New Issue
Block a user