upsert tests and mark complete in bulk

This commit is contained in:
2026-06-03 14:42:00 -04:00
parent 45e600612e
commit 820ae5d50a
2 changed files with 53 additions and 22 deletions
+25 -7
View File
@@ -104,9 +104,12 @@ def del_config(key):
_conn.execute("DELETE FROM config WHERE key = ?", (key,))
def upsert_test(test):
def upsert_tests(tests):
if not tests:
return
with _tx():
_conn.execute(
_conn.executemany(
"""
INSERT INTO tests
(id, test_id, parent_dir, filename, interference, device, rotation,
@@ -130,14 +133,29 @@ def upsert_test(test):
direction = excluded.direction,
throttled = excluded.throttled
""",
test,
tests,
)
def mark_completed(test_id, device, completed_at, duration_seconds, tput_results=None):
json_value = json.dumps(tput_results) if tput_results else None
def mark_tests_completed(records):
if not records:
return
payload = []
for record in records:
payload.append(
(
record.get("completed_at"),
record.get("duration_seconds"),
json.dumps(record.get("tput_results")) if record.get("tput_results") else None,
record.get("test_id"),
record.get("device"),
record.get("device"),
)
)
with _tx():
_conn.execute(
_conn.executemany(
"""
UPDATE tests
SET completed = 1,
@@ -147,7 +165,7 @@ def mark_completed(test_id, device, completed_at, duration_seconds, tput_results
WHERE test_id = ?
AND (? IS NULL OR device = ?)
""",
(completed_at, duration_seconds, json_value, test_id, device, device),
payload,
)