diff --git a/internal/mysql/devicerepo.go b/internal/mysql/devicerepo.go index 9892e64..ad72759 100644 --- a/internal/mysql/devicerepo.go +++ b/internal/mysql/devicerepo.go @@ -296,8 +296,13 @@ func (r *DeviceRepo) populate(ctx context.Context, records []deviceRecord) ([]mo return nil, dbErr(err) } + hasAdded := make(map[int]bool, len(records)) devices := make([]models.Device, 0, len(records)) for _, record := range records { + if hasAdded[record.ID] { + continue + } + device := models.Device{ ID: record.ID, BridgeID: record.BridgeID, @@ -361,6 +366,7 @@ func (r *DeviceRepo) populate(ctx context.Context, records []deviceRecord) ([]mo } } + hasAdded[record.ID] = true devices = append(devices, device) }