| 1002 | } |
| 1003 | |
| 1004 | func sendChanges(ctx context.DnoteCtx, tx *database.DB) (bool, error) { |
| 1005 | log.Info("sending changes.") |
| 1006 | |
| 1007 | var delta int |
| 1008 | err := tx.QueryRow("SELECT (SELECT count(*) FROM notes WHERE dirty) + (SELECT count(*) FROM books WHERE dirty)").Scan(&delta) |
| 1009 | |
| 1010 | fmt.Printf(" (total %d).", delta) |
| 1011 | |
| 1012 | log.DebugNewline() |
| 1013 | |
| 1014 | behind1, err := sendBooks(ctx, tx) |
| 1015 | if err != nil { |
| 1016 | return behind1, errors.Wrap(err, "sending books") |
| 1017 | } |
| 1018 | |
| 1019 | behind2, err := sendNotes(ctx, tx) |
| 1020 | if err != nil { |
| 1021 | return behind2, errors.Wrap(err, "sending notes") |
| 1022 | } |
| 1023 | |
| 1024 | fmt.Println(" done.") |
| 1025 | |
| 1026 | isBehind := behind1 || behind2 |
| 1027 | |
| 1028 | return isBehind, nil |
| 1029 | } |
| 1030 | |
| 1031 | func updateLastMaxUSN(tx *database.DB, val int) error { |
| 1032 | if err := database.UpdateSystem(tx, consts.SystemLastMaxUSN, val); err != nil { |