improvements to sync logic
All checks were successful
build and deploy kleinTodo / build (push) Successful in 14s

This commit is contained in:
Darius klein 2026-01-11 19:04:18 +01:00
parent 28393ee46e
commit 579015cd7b
2 changed files with 28 additions and 7 deletions

View File

@ -80,3 +80,10 @@ func (t Todo) IsEqual(other Todo) bool {
t.Owner == other.Owner && t.Owner == other.Owner &&
t.Deleted == other.Deleted t.Deleted == other.Deleted
} }
func (t Todo) IsEqualIgnoringStatus(other Todo) bool {
return t.Name == other.Name &&
t.Description == other.Description &&
t.Owner == other.Owner &&
t.Deleted == other.Deleted
}

View File

@ -35,19 +35,33 @@ func SyncHandler(w http.ResponseWriter, r *http.Request) {
for _, clientTodo := range todoList.Todos { for _, clientTodo := range todoList.Todos {
serverTodo, exists := serverTodos[clientTodo.Name] serverTodo, exists := serverTodos[clientTodo.Name]
if clientTodo.Deleted && clientTodo.LastModified.After(serverTodo.LastModified) { if !exists {
err = store.RemoveValueFromBucket(user, clientTodo.Name) if clientTodo.Deleted {
if handleError(w, http.StatusInternalServerError, err) { continue
return
} }
} else if !exists {
err = clientTodo.Store(store, user) err = clientTodo.Store(store, user)
if handleError(w, http.StatusInternalServerError, err) { if handleError(w, http.StatusInternalServerError, err) {
return return
} }
serverTodos[clientTodo.Name] = clientTodo serverTodos[clientTodo.Name] = clientTodo
} else { continue
if !serverTodo.IsEqual(clientTodo) { }
if clientTodo.Deleted {
if clientTodo.LastModified.After(serverTodo.LastModified) {
err = store.RemoveValueFromBucket(user, clientTodo.Name)
if handleError(w, http.StatusInternalServerError, err) {
return
}
delete(serverTodos, clientTodo.Name)
}
} else if !serverTodo.IsEqual(clientTodo) {
if serverTodo.IsEqualIgnoringStatus(clientTodo) && clientTodo.LastModified.After(serverTodo.LastModified) {
err = clientTodo.Store(store, user)
if handleError(w, http.StatusInternalServerError, err) {
return
}
serverTodos[clientTodo.Name] = clientTodo
} else {
response.MisMatchingTodos = append(response.MisMatchingTodos, common.MisMatchingTodo{ response.MisMatchingTodos = append(response.MisMatchingTodos, common.MisMatchingTodo{
ServerTodo: serverTodo, ServerTodo: serverTodo,
LocalTodo: clientTodo, LocalTodo: clientTodo,