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

Function cleanLocalNotes

pkg/cli/cmd/sync/sync.go:548–571  ·  view source on GitHub ↗

cleanLocalNotes deletes from the local database any notes that are in invalid state judging by the full list of resources in the server. Concretely, the only acceptable situation in which a local note is not present in the server is if it is new and has not been uploaded (i.e. dirty and usn is 0). O

(tx *database.DB, fullList *syncList)

Source from the content-addressed store, hash-verified

546// situation in which a local note is not present in the server is if it is new and has not been
547// uploaded (i.e. dirty and usn is 0). Otherwise, it is a result of some kind of error and should be cleaned.
548func cleanLocalNotes(tx *database.DB, fullList *syncList) error {
549 rows, err := tx.Query("SELECT uuid, usn, dirty FROM notes")
550 if err != nil {
551 return errors.Wrap(err, "getting local notes")
552 }
553 defer rows.Close()
554
555 for rows.Next() {
556 var note database.Note
557 if err := rows.Scan(&note.UUID, &note.USN, &note.Dirty); err != nil {
558 return errors.Wrap(err, "scanning a row for local note")
559 }
560
561 ok := checkNoteInList(note.UUID, fullList)
562 if !ok && (!note.Dirty || note.USN != 0) {
563 err = note.Expunge(tx)
564 if err != nil {
565 return errors.Wrap(err, "expunging a note")
566 }
567 }
568 }
569
570 return nil
571}
572
573// cleanLocalBooks deletes from the local database any books that are in invalid state
574func cleanLocalBooks(tx *database.DB, fullList *syncList) error {

Callers 2

fullSyncFunction · 0.85
TestCleanLocalNotesFunction · 0.85

Calls 4

ExpungeMethod · 0.95
checkNoteInListFunction · 0.85
QueryMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestCleanLocalNotesFunction · 0.68