Visitar URL original
perf(files): page the Files browser and resolve files without listing the workspace by waleedlatif1 · Pull Request #9436 · simstudioai/sim · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
b58d9a0
feat(files): search and filter the paged file list by kind, size, and…
waleedlatif1 Oct 29, 2026
1b9376f
perf(files): page the Files browser and resolve files by lookup inste…
waleedlatif1 Oct 29, 2026
da95a83
fix(files): settle deleted files, refused lookups, and stale saved fi…
waleedlatif1 Oct 29, 2026
8ba63c5
feat(files): sort the paged list by type and owner, and rank file sea…
waleedlatif1 Oct 29, 2026
19e36df
feat(files): offer the Type and Owner sorts again on the paged browser
waleedlatif1 Oct 29, 2026
f76c9d3
refactor(files): share the file browsers' type rules and tighten the …
waleedlatif1 Oct 29, 2026
2156cce
perf(files): roll up the child folders of several parents in one fold…
waleedlatif1 Oct 29, 2026
1d14e47
refactor(files): consolidate the paged file reads' client hooks and n…
waleedlatif1 Oct 29, 2026
dde3796
perf(files): resolve a file chip's candidates by reference alone
waleedlatif1 Oct 29, 2026
c94cf78
chore(files): tidy the paged file reads' memos, query options, and co…
waleedlatif1 Oct 29, 2026
adc7f97
test(files): tighten the paged file reads' tests
waleedlatif1 Oct 29, 2026
cd527cd
test(files): drop a redundant global unstub and the deleted queries t…
waleedlatif1 Oct 29, 2026
03d3162
fix(files): address the paged file reads' first review round
waleedlatif1 Oct 29, 2026
6cd7537
fix(files): address the paged file reads' second review round
waleedlatif1 Oct 29, 2026
fcd000a
fix(files): address the paged file reads' third review round
waleedlatif1 Oct 29, 2026
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
Prev Previous commit
Next Next commit
perf(files): resolve a file chip's candidates by reference alone
A reference lookup matches an exact id before a path or name, so the separate id lookup per
candidate found nothing the reference did not. Each candidate is now one reference lookup, plus
the name search that keeps a shared name ambiguous; the de-duplicator is the shared one.
  • Loading branch information
waleedlatif1 committed Oct 29, 2026
commit dde3796db59ae726427d00eacc41ada856bb06e1
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,20 @@ describe('fetchWorkspaceResourceRef', () => {
)
).toHaveLength(1)
})

it('asks for each candidate once, as a reference, which already answers an exact id', async () => {
serveWorkspace([file({ id: 'wf_a', name: 'notes.md' })])
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })

await expect(
fetchWorkspaceResourceRef(client, 'ws-1', ref({ id: 'wf_a' }))
).resolves.toMatchObject({ id: 'wf_a' })
const lookups = apiClientRequestMockFns.mockRequestJson.mock.calls.filter(
([contract]) => contract === lookupWorkspaceFilesContract
)
expect(lookups).toHaveLength(1)
const body = (lookups[0][1] as { body: Record<string, unknown> }).body
expect(body.ids ?? []).toEqual([])
expect(body.references).toEqual(expect.arrayContaining(['wf_a']))
})
})
19 changes: 4 additions & 15 deletions apps/sim/app/workspace/[workspaceId]/home/resolve-resource-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { canonicalWorkspaceFilePath } from '@/lib/mothership/vfs/path-utils'
import type { WorkspaceFileRecord } from '@/lib/uploads/contexts/workspace'
import { findWorkspaceFileByPath } from '@/hooks/queries/utils/find-workspace-file-by-src'
import {
distinctFiles,
getWorkspaceFileLookupQueryOptions,
getWorkspaceFileSearchQueryOptions,
} from '@/hooks/queries/workspace-files'
Expand Down Expand Up @@ -96,13 +97,12 @@ function fileRefCandidates(ref: WorkspaceResourceRef): string[] {

/**
* The reads that together hold every file a chip's candidates can match under
* {@link resolveWorkspaceResourceRef}'s rules: each candidate as an exact id, as a reference (an
* exact VFS path resolves first), and — for a candidate that could be a bare name — every file
* whose name contains it, so a name shared by two files is still seen as ambiguous.
* {@link resolveWorkspaceResourceRef}'s rules: each candidate as a reference (an exact id
* resolves first, then an exact VFS path), and — for a candidate that could be a bare name —
* every file whose name contains it, so a name shared by two files is still seen as ambiguous.
*/
function fileRefReads(queryClient: QueryClient, workspaceId: string, ref: WorkspaceResourceRef) {
return fileRefCandidates(ref).flatMap((candidate) => [
getWorkspaceFileLookupQueryOptions(queryClient, workspaceId, 'id', candidate),
getWorkspaceFileLookupQueryOptions(queryClient, workspaceId, 'reference', candidate),
...(candidate.includes('/') || candidate.length > V2_SEARCH_MAX_LENGTH
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
? []
Expand All @@ -115,17 +115,6 @@ function fileRefReads(queryClient: QueryClient, workspaceId: string, ref: Worksp
])
}

/** The distinct files several reads returned: one file found by two reads is still one file. */
function distinctFiles(
reads: readonly (WorkspaceFileRecord | WorkspaceFileRecord[] | null)[]
): WorkspaceFileRecord[] {
const files = new Map<string, WorkspaceFileRecord>()
for (const data of reads) {
for (const file of Array.isArray(data) ? data : data ? [data] : []) files.set(file.id, file)
}
return [...files.values()]
}

/**
* Resolves a chip against the workspace's live files, fetching only the handful of files its
* candidates can name rather than the workspace's list. `fresh` re-reads them all: a chip may
Expand Down