diff --git a/internal/storage/local.go b/internal/storage/local.go index 5f92946..c2d1958 100644 --- a/internal/storage/local.go +++ b/internal/storage/local.go @@ -2,6 +2,7 @@ package storage import ( "errors" + "sort" "time" "git.ewintr.nl/gte/internal/task" @@ -26,6 +27,7 @@ func NextLocalId(used []int) int { return 1 } + sort.Ints(used) usedMax := 1 for _, u := range used { if u > usedMax { diff --git a/internal/storage/local_test.go b/internal/storage/local_test.go index 030b7a3..2011adc 100644 --- a/internal/storage/local_test.go +++ b/internal/storage/local_test.go @@ -58,6 +58,14 @@ func TestNextLocalId(t *testing.T) { used: []int{99}, exp: 1, }, + { + name: "sync bug", + used: []int{151, 956, 955, 150, 154, 155, 145, 144, + 136, 152, 148, 146, 934, 149, 937, 135, 140, 139, + 143, 137, 153, 939, 138, 953, 147, 141, 938, 142, + }, + exp: 957, + }, } { t.Run(tc.name, func(t *testing.T) { test.Equals(t, tc.exp, storage.NextLocalId(tc.used)) diff --git a/internal/storage/sqlite.go b/internal/storage/sqlite.go index 9eb48e2..4e414d6 100644 --- a/internal/storage/sqlite.go +++ b/internal/storage/sqlite.go @@ -120,6 +120,7 @@ VALUES used = append(used, localId) } } + for id, localId := range localIdMap { if localId == 0 { newLocalId := NextLocalId(used)