( root: string, source: 'builtin' | 'ripgrep', paths: Required<VaultTextSearchToolPaths>, collect: () => Promise<VaultTextSearchCandidate[]> )
| 1875 | } |
| 1876 | |
| 1877 | async 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 | |
| 1912 | async function searchExecutable( |
| 1913 | kind: 'ripgrep' | 'fzf', |
no test coverage detected