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

Function saveSyncState

pkg/cli/cmd/sync/sync.go:1047–1070  ·  view source on GitHub ↗
(tx *database.DB, serverTime int64, serverMaxUSN int, userMaxUSN int)

Source from the content-addressed store, hash-verified

1045}
1046
1047func saveSyncState(tx *database.DB, serverTime int64, serverMaxUSN int, userMaxUSN int) error {
1048 // Handle last_max_usn update based on server state:
1049 // - If serverMaxUSN > 0: we got data, update to serverMaxUSN
1050 // - If serverMaxUSN == 0 && userMaxUSN > 0: empty fragment (caught up), preserve existing
1051 // - If serverMaxUSN == 0 && userMaxUSN == 0: empty server, reset to 0
1052 if serverMaxUSN > 0 {
1053 if err := updateLastMaxUSN(tx, serverMaxUSN); err != nil {
1054 return errors.Wrap(err, "updating last max usn")
1055 }
1056 } else if userMaxUSN == 0 {
1057 // Server is empty, reset to 0
1058 if err := updateLastMaxUSN(tx, 0); err != nil {
1059 return errors.Wrap(err, "updating last max usn")
1060 }
1061 }
1062 // else: empty fragment but server has data, preserve existing last_max_usn
1063
1064 // Always update last_sync_at (we did communicate with server)
1065 if err := updateLastSyncAt(tx, serverTime); err != nil {
1066 return errors.Wrap(err, "updating last sync at")
1067 }
1068
1069 return nil
1070}
1071
1072// prepareEmptyServerSync marks all local books and notes as dirty when syncing to an empty server.
1073// This is typically used when switching to a new empty server but wanting to upload existing local data.

Callers 3

fullSyncFunction · 0.85
stepSyncFunction · 0.85
TestSaveServerStateFunction · 0.85

Calls 2

updateLastMaxUSNFunction · 0.85
updateLastSyncAtFunction · 0.85

Tested by 1

TestSaveServerStateFunction · 0.68