MCPcopy Create free account
hub / github.com/blues/note / GetChangedNotefiles

Method GetChangedNotefiles

lib/notebox.go:654–709  ·  view source on GitHub ↗

GetChangedNotefiles determines, for a given tracker, if there are changes in any notebox and, if so, for which ones. NOTE that after significant performance measurement in Aug 2024 it became clear that this method would be far, far more efficient if we would design a box.OpenNotefiles() method that

(ctx context.Context, endpointID string)

Source from the content-addressed store, hash-verified

652// be a great addition, specifically because the msgNoteboxSummary transaction is done at the beginning
653// of each and every sync and thus is inherently a hotspot.
654func (box *Notebox) GetChangedNotefiles(ctx context.Context, endpointID string) (changedNotefiles []string) {
655
656 // Get the names of all possible openable Notefiles
657 allNotefiles := box.Notefiles(true)
658
659 // Add the local endpoint, because that's explicitly not included in the list
660 allNotefiles = append(allNotefiles, box.instance.endpointID)
661
662 // Get the notefile info of the "source" and "destination" for the changes
663 sourceEndpointID := box.instance.endpointID
664 destinationEndpointID := endpointID
665
666 // Enum the notefiles, looking for changes
667 changedNotefiles = []string{}
668 for i := range allNotefiles {
669 notefileID := allNotefiles[i]
670 openfile, file, err := box.OpenNotefile(ctx, notefileID)
671 if err == nil {
672 info, err := box.GetNotefileInfo(notefileID)
673 if err != nil {
674 info = note.NotefileInfo{}
675 }
676 suppress := false
677 hubEndpointID := info.SyncHubEndpointID
678 if info.SyncHubEndpointID == "" {
679 hubEndpointID = note.DefaultHubEndpointID
680 }
681 isQueue, syncToHub, syncFromHub, _, _, _ := NotefileAttributesFromID(notefileID)
682 if isQueue && syncToHub {
683 suppress = true
684 }
685 if !syncToHub && hubEndpointID == destinationEndpointID {
686 suppress = true
687 }
688 if !syncFromHub && hubEndpointID == sourceEndpointID {
689 suppress = true
690 }
691 // If the file has never been tracked, we need to mark it as changed regardless
692 // of whether or not it is "push" or "pull".
693 if !file.IsTracker(endpointID) {
694 suppress = false
695 }
696 // If not suppressing, return true only if the file has been changed
697 if !suppress {
698 areFileChanges, err := file.AreChanges(endpointID)
699 if err == nil && areFileChanges {
700 changedNotefiles = append(changedNotefiles, notefileID)
701 }
702 }
703 openfile.Close(ctx)
704 }
705 }
706
707 // Done
708 return changedNotefiles
709}
710
711// Close releases a notebox, but leaves it in-memory with a 0 refcount for low-overhead re-open

Callers 2

RequestMethod · 0.95
hubNoteboxSummaryFunction · 0.80

Calls 7

NotefilesMethod · 0.95
OpenNotefileMethod · 0.95
GetNotefileInfoMethod · 0.95
NotefileAttributesFromIDFunction · 0.85
IsTrackerMethod · 0.80
AreChangesMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected