Skip to content

Commit

Permalink
Fix issue where sync hard fails when device has no existing sync groups
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtyped committed Apr 16, 2024
1 parent a877db6 commit 941e783
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ func (s *SubscriptionAPI) HandleUploadDeviceSubscriptionChange(w http.ResponseWr
return
}

if syncDevices == nil {
syncDevices = []int{deviceId}
}

pairz := []Pair{}
for _, v := range addSlice {
sub := data.Subscription{
Expand Down
12 changes: 9 additions & 3 deletions pkg/data/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ func unique(stringSlice []string) []string {
}

// GetDevicesInSyncGroupFromDeviceId takes in a deviceId and returns a list of
// deviceIds that belongs to the same syncgroup including itself
// deviceIds that belongs to the same syncgroup including itself. If there's no
// sync group, it should return a nil to signal that the device has no existing
// sync_group, but not return an error as it is returning a valid position.
func (s *SQLite) GetDevicesInSyncGroupFromDeviceId(deviceId int) ([]int, error) {

var deviceSyncGroupId int
Expand All @@ -393,8 +395,12 @@ func (s *SQLite) GetDevicesInSyncGroupFromDeviceId(deviceId int) ([]int, error)
// get the sync group id
err := db.QueryRow("select device_sync_group_id from device_sync_group_devices where device_id =? LIMIT 1", deviceId).Scan(&deviceSyncGroupId)
if err != nil {
log.Printf("error getting device_sync_group_id: %#v", err)
return nil, err
if err == sql.ErrNoRows {
return nil, nil
} else {
log.Printf("error getting device_sync_group_id: %#v", err)
return nil, err
}
}

rows, err := db.Query("select device_id from device_sync_group_devices WHERE device_sync_group_id = ?", deviceSyncGroupId)
Expand Down

0 comments on commit 941e783

Please sign in to comment.