MCPcopy
hub / github.com/dnote/dnote / fullSync

Function fullSync

pkg/cli/cmd/sync/sync.go:599–652  ·  view source on GitHub ↗
(ctx context.DnoteCtx, tx *database.DB)

Source from the content-addressed store, hash-verified

597}
598
599func fullSync(ctx context.DnoteCtx, tx *database.DB) error {
600 log.Debug("performing a full sync\n")
601 log.Info("resolving delta.")
602
603 log.DebugNewline()
604
605 list, err := getSyncList(ctx, 0)
606 if err != nil {
607 return errors.Wrap(err, "getting sync list")
608 }
609
610 fmt.Printf(" (total %d).", list.getLength())
611
612 log.DebugNewline()
613
614 // clean resources that are in erroneous states
615 if err := cleanLocalNotes(tx, &list); err != nil {
616 return errors.Wrap(err, "cleaning up local notes")
617 }
618 if err := cleanLocalBooks(tx, &list); err != nil {
619 return errors.Wrap(err, "cleaning up local books")
620 }
621
622 for _, note := range list.Notes {
623 if err := fullSyncNote(tx, note); err != nil {
624 return errors.Wrap(err, "merging note")
625 }
626 }
627 for _, book := range list.Books {
628 if err := fullSyncBook(tx, book); err != nil {
629 return errors.Wrap(err, "merging book")
630 }
631 }
632
633 for noteUUID := range list.ExpungedNotes {
634 if err := syncDeleteNote(tx, noteUUID); err != nil {
635 return errors.Wrap(err, "deleting note")
636 }
637 }
638 for bookUUID := range list.ExpungedBooks {
639 if err := syncDeleteBook(tx, bookUUID); err != nil {
640 return errors.Wrap(err, "deleting book")
641 }
642 }
643
644 err = saveSyncState(tx, list.MaxCurrentTime, list.MaxUSN, list.UserMaxUSN)
645 if err != nil {
646 return errors.Wrap(err, "saving sync state")
647 }
648
649 fmt.Println(" done.")
650
651 return nil
652}
653
654func stepSync(ctx context.DnoteCtx, tx *database.DB, afterUSN int) error {
655 log.Debug("performing a step sync\n")

Callers 1

newRunFunction · 0.85

Calls 12

DebugFunction · 0.92
InfoFunction · 0.92
DebugNewlineFunction · 0.92
getSyncListFunction · 0.85
cleanLocalNotesFunction · 0.85
cleanLocalBooksFunction · 0.85
fullSyncNoteFunction · 0.85
fullSyncBookFunction · 0.85
syncDeleteNoteFunction · 0.85
syncDeleteBookFunction · 0.85
saveSyncStateFunction · 0.85
getLengthMethod · 0.80

Tested by

no test coverage detected