()
| 665 | } |
| 666 | |
| 667 | func (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 | |
| 711 | func (v *Vault) persistNoteMetaCacheSnapshot(metas []NoteMeta) { |
| 712 | if os.Getenv("ZEN_PERF_DISABLE_PERSISTED_META_CACHE") == "1" { |
no test coverage detected