From cd0742cbaa8a01a1f3e8a02010a65ec878c80dc1 Mon Sep 17 00:00:00 2001 From: Fabian Posch Date: Sun, 2 Feb 2025 20:28:40 +0100 Subject: [PATCH] change from view to prepared statement --- src/actsim_agent/downloader.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/actsim_agent/downloader.cpp b/src/actsim_agent/downloader.cpp index 0cb71f7..0ad3daa 100644 --- a/src/actsim_agent/downloader.cpp +++ b/src/actsim_agent/downloader.cpp @@ -71,8 +71,29 @@ void Downloader::thread_run() { return; } - this->conn->prepare_statement("mark_tasks", - "UPDATE sim_configs SET part_status = 'finished' WHERE id = $1;" + this->conn->prepare_statements({ + {"mark_tasks", "UPDATE sim_configs SET part_status = 'finished' WHERE id = $1;"}, + {"fetch_tasks", + "SELECT " + " ap.design_file AS design, " + " ap.top_proc, " + " ap.outputs AS target_artifact, " + " ap.id AS source_pass, " + " sc.id AS source_config, " + " sc.sim_commands, " + " sc.has_reference AS reference, " + " sc.part_status " + "FROM " + " sim_configs sc " + "JOIN " + " actsim_passes ap ON sc.artifact = ap.sim_configs " + "LEFT JOIN " + " sim_outputs so ON sc.has_reference = so.sim_config " + "WHERE " + " sc.part_status = 'not_started' " + " AND (sc.has_reference IS NULL OR so.part_status = 'finished') " + "LIMIT $1;" } + } ); while (this->interface.running()) { @@ -120,12 +141,7 @@ bool Downloader::fetch_tasks(size_t n) { pqxx::result res; try { - res = txn.exec( - "SELECT * " - "FROM open_tasks " - "LIMIT $1;", - n - ); + res = txn.exec(pqxx::prepped("fetch_tasks"), n); for (auto&& row : res) { txn.exec(pqxx::prepped("mark_tasks"), {row["source_config"].as()});