fix: review findings (async SQS dispatcher, backoff, batch insert, shutdown order, pagination, HMAC) + loadtest fixes; v0.1.6

This commit is contained in:
“Naeel”
2026-08-16 18:24:09 +04:00
parent 090cedca67
commit 3fedf9317c
27 changed files with 581 additions and 122 deletions
+15 -5
View File
@@ -29,12 +29,22 @@ VALUES ($1, $2, $3, $4, $5, $6)`,
return nil
}
// List возвращает устройства namespace (без сортировки по паролям — пароли на месте, но API их не отдаёт).
func (s *DeviceStore) List(ctx context.Context, namespace string) ([]Device, error) {
rows, err := s.db.QueryContext(ctx, `
SELECT namespace, name, device_id, enabled, mqtt_password, metadata, phase,
// List возвращает устройства namespace (без паролей — API их не отдаёт).
// limit <= 0 — без ограничения; offset — смещение (пагинация API).
func (s *DeviceStore) List(ctx context.Context, namespace string, limit, offset int) ([]Device, error) {
query := `SELECT namespace, name, device_id, enabled, mqtt_password, metadata, phase,
last_connected, created_at
FROM iot_devices WHERE namespace = $1 ORDER BY name`, namespace)
FROM iot_devices WHERE namespace = $1 ORDER BY name`
args := []any{namespace}
if limit > 0 {
query += fmt.Sprintf(" LIMIT $%d", len(args)+1)
args = append(args, limit)
}
if offset > 0 {
query += fmt.Sprintf(" OFFSET $%d", len(args)+1)
args = append(args, offset)
}
rows, err := s.db.QueryContext(ctx, query, args...)
if err != nil {
return nil, fmt.Errorf("store: list devices: %w", err)
}