change from view to prepared statement

This commit is contained in:
Fabian Posch 2025-02-02 20:28:40 +01:00
parent d3f88a8acd
commit cd0742cbaa

View file

@ -71,8 +71,29 @@ void Downloader::thread_run() {
return; return;
} }
this->conn->prepare_statement("mark_tasks", this->conn->prepare_statements({
"UPDATE sim_configs SET part_status = 'finished' WHERE id = $1;" {"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()) { while (this->interface.running()) {
@ -120,12 +141,7 @@ bool Downloader::fetch_tasks(size_t n) {
pqxx::result res; pqxx::result res;
try { try {
res = txn.exec( res = txn.exec(pqxx::prepped("fetch_tasks"), n);
"SELECT * "
"FROM open_tasks "
"LIMIT $1;",
n
);
for (auto&& row : res) { for (auto&& row : res) {
txn.exec(pqxx::prepped("mark_tasks"), {row["source_config"].as<db::uuid_t>()}); txn.exec(pqxx::prepped("mark_tasks"), {row["source_config"].as<db::uuid_t>()});