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

Function hydratePersistedNoteMetaCache

apps/desktop/src/main/vault.ts:1748–1792  ·  view source on GitHub ↗
(root: string)

Source from the content-addressed store, hash-verified

1746}
1747
1748async 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
1794function snapshotNoteMetaCache(root: string, metas: NoteMeta[]): Array<{
1795 path: string

Callers 1

listNotesFunction · 0.85

Calls 4

noteMetaCachePathFunction · 0.85
normalizeCachedNoteMetaFunction · 0.85
noteMetaCacheKeyFunction · 0.85
resolveSafeFunction · 0.70

Tested by

no test coverage detected