fix: avoid note-window vault scans

This commit is contained in:
lucaronin
2026-05-14 04:53:19 +02:00
parent 9d9681345d
commit 6bb9c7fbc9
3 changed files with 43 additions and 11 deletions

View File

@@ -132,7 +132,13 @@ const relatedEntry = makeEntry({
title: 'Software Development',
isA: 'Topic',
})
const entries = [activeEntry, relatedEntry]
const secondEntry = makeEntry({
path: '/vault/project/second.md',
filename: 'second.md',
title: 'Second Project',
isA: 'Project',
})
const entries = [activeEntry, relatedEntry, secondEntry]
const noteContent = '---\ntitle: Test Project\ntype: Project\n---\n\n# Test Project\n'
const defaultVaultPath = DEFAULT_VAULTS[0].path || '/Users/mock/Documents/Getting Started'
@@ -215,7 +221,7 @@ describe('App note windows', () => {
)
})
it('passes the loaded vault index to the editor in note windows', async () => {
it('keeps note windows scoped to the active entry without loading the vault index', async () => {
renderApp(<App />)
await waitFor(() => {
@@ -224,18 +230,44 @@ describe('App note windows', () => {
vaultPath: '/vault',
})
})
await waitFor(() => {
expect(commandResults.list_vault).toHaveBeenCalledWith({ path: '/vault' })
})
expect(commandResults.list_vault).not.toHaveBeenCalled()
await waitFor(() => {
expect(screen.getByTestId('mock-editor-entry-titles')).toHaveTextContent(
'Test Project|Software Development',
'Test Project',
)
})
expect(editorSnapshots.at(-1)).toEqual({
activeTabPath: activeEntry.path,
entryTitles: ['Test Project', 'Software Development'],
entryTitles: ['Test Project'],
})
})
it('opens repeated note windows without repeated full-vault scans', async () => {
const firstWindow = renderApp(<App />)
await waitFor(() => {
expect(commandResults.reload_vault_entry).toHaveBeenCalledWith({
path: activeEntry.path,
vaultPath: '/vault',
})
})
firstWindow.unmount()
window.history.replaceState(
{},
'',
'/?window=note&path=%2Fvault%2Fproject%2Fsecond.md&vault=%2Fvault&title=Second+Project',
)
renderApp(<App />)
await waitFor(() => {
expect(commandResults.reload_vault_entry).toHaveBeenCalledWith({
path: secondEntry.path,
vaultPath: '/vault',
})
})
expect(commandResults.reload_vault_entry).toHaveBeenCalledTimes(2)
expect(commandResults.list_vault).not.toHaveBeenCalled()
})
})

View File

@@ -576,7 +576,7 @@ describe('App', () => {
})
})
it('opens a note window by loading the requested entry and vault index', async () => {
it('opens a note window by loading only the requested entry', async () => {
const listVault = vi.fn(() => mockEntries)
const reloadVaultEntry = vi.fn(({ path }: { path: string }) =>
mockEntries.find((entry) => entry.path === path) ?? null,
@@ -599,7 +599,7 @@ describe('App', () => {
expect(getNoteContent).toHaveBeenCalledWith({ path: '/vault/project/test.md', vaultPath: '/vault' })
await waitFor(() => expect(window.__laputaTest?.activeTabPath).toBe('/vault/project/test.md'))
expect(screen.getByTestId('blocknote-view')).toHaveAttribute('data-editable', 'true')
expect(listVault).toHaveBeenCalledWith({ path: '/vault' })
expect(listVault).not.toHaveBeenCalled()
})
it('shows keyboard shortcut hints', async () => {

View File

@@ -368,7 +368,7 @@ function App() {
})
const vault = useVaultLoader(
resolvedPath,
noteWindowParams ? '' : resolvedPath,
graphVaults,
multiWorkspaceEnabled ? defaultWorkspacePath : null,
folderVaults,
@@ -1687,7 +1687,7 @@ function App() {
tabs={notes.tabs}
activeTabPath={notes.activeTabPath}
isVaultLoading={isVaultContentLoading}
entries={visibleEntries}
entries={noteWindowParams && activeTab ? [activeTab.entry] : visibleEntries}
onNavigateWikilink={notes.handleNavigateWikilink}
onLoadDiff={loadDiffForPath}
onLoadDiffAtCommit={loadDiffAtCommitForPath}