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

Method hydratePersistedNoteMetaCache

apps/server/internal/vault/vault.go:667–709  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

665}
666
667func (v *Vault) hydratePersistedNoteMetaCache() {
668 v.metaCacheMu.Lock()
669 if v.metaCacheLoad {
670 v.metaCacheMu.Unlock()
671 return
672 }
673 v.metaCacheLoad = true
674 v.metaCacheMu.Unlock()
675
676 raw, err := os.ReadFile(v.noteMetaCachePath())
677 if err != nil {
678 return
679 }
680 var persisted persistedNoteMetaCache
681 if err := json.Unmarshal(raw, &persisted); err != nil || persisted.Version != noteMetaCacheVersion {
682 return
683 }
684
685 entries := map[string]noteMetaCacheEntry{}
686 for _, entry := range persisted.Entries {
687 if entry.Path == "" || !validCachedNoteMeta(entry.Meta, entry.Path) {
688 continue
689 }
690 abs, err := SafeJoin(v.root, entry.Path)
691 if err != nil {
692 continue
693 }
694 entries[abs] = noteMetaCacheEntry{
695 mtimeMs: entry.MtimeMs,
696 size: entry.Size,
697 meta: entry.Meta,
698 }
699 }
700 if len(entries) == 0 {
701 return
702 }
703
704 v.metaCacheMu.Lock()
705 for key, entry := range entries {
706 v.metaCache[key] = entry
707 }
708 v.metaCacheMu.Unlock()
709}
710
711func (v *Vault) persistNoteMetaCacheSnapshot(metas []NoteMeta) {
712 if os.Getenv("ZEN_PERF_DISABLE_PERSISTED_META_CACHE") == "1" {

Callers 1

ListNotesMethod · 0.95

Calls 3

noteMetaCachePathMethod · 0.95
validCachedNoteMetaFunction · 0.85
SafeJoinFunction · 0.85

Tested by

no test coverage detected