(root: string)
| 1746 | } |
| 1747 | |
| 1748 | async function hydratePersistedNoteMetaCache(root: string): Promise<void> { |
| 1749 | const rootAbs = path.resolve(root) |
| 1750 | if (loadedPersistedNoteMetaCacheRoots.has(rootAbs)) return |
| 1751 | loadedPersistedNoteMetaCacheRoots.add(rootAbs) |
| 1752 | |
| 1753 | try { |
| 1754 | const raw = await fs.readFile(noteMetaCachePath(root), 'utf8') |
| 1755 | const parsed = JSON.parse(raw) as { |
| 1756 | version?: unknown |
| 1757 | entries?: unknown |
| 1758 | } |
| 1759 | if (parsed.version !== NOTE_META_CACHE_VERSION || !Array.isArray(parsed.entries)) return |
| 1760 | |
| 1761 | for (const entry of parsed.entries) { |
| 1762 | if (!entry || typeof entry !== 'object') continue |
| 1763 | const candidate = entry as { |
| 1764 | path?: unknown |
| 1765 | mtimeMs?: unknown |
| 1766 | size?: unknown |
| 1767 | meta?: unknown |
| 1768 | } |
| 1769 | if ( |
| 1770 | typeof candidate.path !== 'string' || |
| 1771 | typeof candidate.mtimeMs !== 'number' || |
| 1772 | typeof candidate.size !== 'number' |
| 1773 | ) { |
| 1774 | continue |
| 1775 | } |
| 1776 | const meta = normalizeCachedNoteMeta(candidate.meta) |
| 1777 | if (!meta || meta.path !== candidate.path) continue |
| 1778 | try { |
| 1779 | const abs = resolveSafe(root, candidate.path) |
| 1780 | noteMetaCache.set(noteMetaCacheKey(root, abs), { |
| 1781 | mtimeMs: candidate.mtimeMs, |
| 1782 | size: candidate.size, |
| 1783 | meta |
| 1784 | }) |
| 1785 | } catch { |
| 1786 | /* ignore invalid cache paths */ |
| 1787 | } |
| 1788 | } |
| 1789 | } catch { |
| 1790 | /* missing or corrupt cache files should never block vault loading */ |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | function snapshotNoteMetaCache(root: string, metas: NoteMeta[]): Array<{ |
| 1795 | path: string |
no test coverage detected