MCPcopy Index your code
hub / github.com/dnote/dnote / cleanLocalBooks

Function cleanLocalBooks

pkg/cli/cmd/sync/sync.go:574–597  ·  view source on GitHub ↗

cleanLocalBooks deletes from the local database any books that are in invalid state

(tx *database.DB, fullList *syncList)

Source from the content-addressed store, hash-verified

572
573// cleanLocalBooks deletes from the local database any books that are in invalid state
574func cleanLocalBooks(tx *database.DB, fullList *syncList) error {
575 rows, err := tx.Query("SELECT uuid, usn, dirty FROM books")
576 if err != nil {
577 return errors.Wrap(err, "getting local books")
578 }
579 defer rows.Close()
580
581 for rows.Next() {
582 var book database.Book
583 if err := rows.Scan(&book.UUID, &book.USN, &book.Dirty); err != nil {
584 return errors.Wrap(err, "scanning a row for local book")
585 }
586
587 ok := checkBookInList(book.UUID, fullList)
588 if !ok && (!book.Dirty || book.USN != 0) {
589 err = book.Expunge(tx)
590 if err != nil {
591 return errors.Wrap(err, "expunging a book")
592 }
593 }
594 }
595
596 return nil
597}
598
599func fullSync(ctx context.DnoteCtx, tx *database.DB) error {
600 log.Debug("performing a full sync\n")

Callers 2

fullSyncFunction · 0.85
TestCleanLocalBooksFunction · 0.85

Calls 4

ExpungeMethod · 0.95
checkBookInListFunction · 0.85
QueryMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestCleanLocalBooksFunction · 0.68