From 10ab5a9bdc0e27691ec2d09772c8e62587b779a7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 15 Feb 2024 13:37:31 +0300 Subject: Cleanup build queries in monitor --- monitor/monitor.cxx | 76 ++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 47 deletions(-) (limited to 'monitor/monitor.cxx') diff --git a/monitor/monitor.cxx b/monitor/monitor.cxx index 77f387b..27e8b84 100644 --- a/monitor/monitor.cxx +++ b/monitor/monitor.cxx @@ -655,8 +655,13 @@ namespace brep conn->prepare_query ("buildable-package-query", pq)); - // Prepare the package configuration build prepared query. + // Prepare the package configuration build prepared queries. // + using bquery = query; + using prep_bquery = prepared_query; + + build_id id; + // This query will only be used for toolchains that have no version // specified on the command line to obtain the latest completed build // across all toolchain versions, if present, and the latest incomplete @@ -667,29 +672,26 @@ namespace brep // toolchain that built the package last and if there are none, pick the // one for which the build task was issued last. // - using bquery = query; - using prep_bquery = prepared_query; - - build_id id; - string package_config_name; - - const auto& bid (bquery::build::id); - - bquery bq ((bquery::build::state != "queued" && - equal (bid.package, id.package) && - bid.target == bquery::_ref (id.target) && - bid.target_config_name == - bquery::_ref (id.target_config_name) && - bid.package_config_name == - bquery::_ref (package_config_name) && - bid.toolchain_name == bquery::_ref (id.toolchain_name)) + - "ORDER BY" + - bquery::build::soft_timestamp + "DESC, " + - bquery::build::timestamp + "DESC" + - "LIMIT 1"); - - prep_bquery pbq ( - conn->prepare_query ("package-build-query", bq)); + // @@ TMP Check if we can optimize this query by adding index for + // soft_timestamp and/or by setting enable_nestloop=off (or some + // such) as we do in mod/mod-builds.cxx. + // + bquery lbq ((equal (bquery::id, + id, + false /* toolchain_version */) && + bquery::state != "queued") + + "ORDER BY" + + bquery::soft_timestamp + "DESC, " + + bquery::timestamp + "DESC" + + "LIMIT 1"); + + prep_bquery plbq ( + conn->prepare_query ("package-latest-build-query", lbq)); + + // This query will only be used to retrieve a specific build by id. + // + bquery bq (equal (bquery::id, id) && bquery::state != "queued"); + prep_bquery pbq (conn->prepare_query ("package-build-query", bq)); timestamp now (system_clock::now ()); @@ -848,29 +850,9 @@ namespace brep // the latest build across all toolchain versions and search // for a specific build otherwise. // - shared_ptr b; - - if (id.toolchain_version.empty ()) - { - package_config_name = pc.name; - - // @@ TMP Check if we can optimize this query by adding - // index for soft_timestamp and/or by setting - // enable_nestloop=off (or some such) as we do in - // mod/mod-builds.cxx. - // - auto pbs (pbq.execute ()); - - if (!pbs.empty ()) - b = move (pbs.begin ()->build); - } - else - { - b = db.find (id); - - if (b->state == build_state::queued) - b = nullptr; - } + shared_ptr b (id.toolchain_version.empty () + ? plbq.execute_one () + : pbq.execute_one ()); // Note that we consider a build as delayed if it is not // completed in the expected timeframe. So even if the build -- cgit v1.1