Index host operations by kind to avoid polling history scans

This commit is contained in:
2026-10-05 08:40:37 -04:00
parent caa7672bec
commit 9472bb5184
2 changed files with 26 additions and 0 deletions
+4
View File
@@ -29,6 +29,10 @@ export function ensureHostSchema(handle: Database.Database): void {
UNIQUE(host_id, idempotency_key)
);
CREATE INDEX IF NOT EXISTS ec_host_operations_queue ON ec_host_operations(host_id, state, created_at);
-- Polling checks cancellations and preparation by kind across retained
-- history. The queue index cannot narrow those lookups beyond host_id,
-- causing a history scan for every queued command on Node's main thread.
CREATE INDEX IF NOT EXISTS ec_host_operations_kind ON ec_host_operations(host_id, kind, created_at);
CREATE TABLE IF NOT EXISTS ec_host_operation_events (
id INTEGER PRIMARY KEY AUTOINCREMENT, operation_id TEXT NOT NULL REFERENCES ec_host_operations(id),
state TEXT NOT NULL, created_at TEXT NOT NULL, error TEXT