MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / getCachedVaultTextSearchCandidates

Function getCachedVaultTextSearchCandidates

apps/desktop/src/main/vault.ts:1877–1910  ·  view source on GitHub ↗
(
  root: string,
  source: 'builtin' | 'ripgrep',
  paths: Required<VaultTextSearchToolPaths>,
  collect: () => Promise<VaultTextSearchCandidate[]>
)

Source from the content-addressed store, hash-verified

1875}
1876
1877async function getCachedVaultTextSearchCandidates(
1878 root: string,
1879 source: 'builtin' | 'ripgrep',
1880 paths: Required<VaultTextSearchToolPaths>,
1881 collect: () => Promise<VaultTextSearchCandidate[]>
1882): Promise<VaultTextSearchCandidate[]> {
1883 const key = candidateCacheKey(root, source, paths)
1884 const now = Date.now()
1885 if (
1886 cachedVaultTextSearchCandidates &&
1887 cachedVaultTextSearchCandidates.key === key &&
1888 now - cachedVaultTextSearchCandidates.at < SEARCH_CANDIDATE_CACHE_TTL_MS
1889 ) {
1890 recordMainPerf('main.vaultTextSearch.candidates.cacheHit', 0, {
1891 source,
1892 candidates: cachedVaultTextSearchCandidates.value.length
1893 })
1894 return cachedVaultTextSearchCandidates.value
1895 }
1896
1897 const startedAt = performance.now()
1898 const value = await collect()
1899 cachedVaultTextSearchCandidates = {
1900 at: Date.now(),
1901 key,
1902 root: path.resolve(root),
1903 value
1904 }
1905 recordMainPerf('main.vaultTextSearch.candidates.refresh', performance.now() - startedAt, {
1906 source,
1907 candidates: value.length
1908 })
1909 return value
1910}
1911
1912async function searchExecutable(
1913 kind: 'ripgrep' | 'fzf',

Callers 1

searchVaultTextFunction · 0.85

Calls 2

recordMainPerfFunction · 0.90
candidateCacheKeyFunction · 0.85

Tested by

no test coverage detected