upsert tests and mark complete in bulk
This commit is contained in:
+25
-7
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user