From 873987793b05fc0d6e9908f5030b2bca145c4e6d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sun, 28 Oct 2018 01:01:53 +0300 Subject: Add tenant object --- mod/mod-build-task.cxx | 2 +- mod/mod-builds.cxx | 59 +++++++++++++++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 23 deletions(-) (limited to 'mod') diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx index 77652ce..d3efb41 100644 --- a/mod/mod-build-task.cxx +++ b/mod/mod-build-task.cxx @@ -328,7 +328,7 @@ handle (request& rq, response& rs) using pkg_query = query; using prep_pkg_query = prepared_query; - pkg_query pq (true); + pkg_query pq (!pkg_query::build_tenant::archived); // Filter by repositories canonical names (if requested). // diff --git a/mod/mod-builds.cxx b/mod/mod-builds.cxx index a55b6f9..4d03987 100644 --- a/mod/mod-builds.cxx +++ b/mod/mod-builds.cxx @@ -94,7 +94,8 @@ template static inline query build_query (const brep::cstrings& configs, const brep::params::builds& params, - const brep::optional& tenant) + const brep::optional& tenant, + const brep::optional& archived) { using namespace brep; using query = query; @@ -109,6 +110,9 @@ build_query (const brep::cstrings& configs, if (tenant) q = q && pid.tenant == *tenant; + if (archived) + q = q && query::build_tenant::archived == *archived; + // Note that there is no error reported if the filter parameters parsing // fails. Instead, it is considered that no package builds match such a // query. @@ -205,18 +209,23 @@ build_query (const brep::cstrings& configs, return q; } -template ::build_package> +template static inline query package_query (const brep::params::builds& params, - const brep::optional& tenant) + const brep::optional& tenant, + const brep::optional& archived) { using namespace brep; using query = query; + using qp = typename query::build_package; query q (true); if (tenant) - q = q && P::id.tenant == *tenant; + q = q && qp::id.tenant == *tenant; + + if (archived) + q = q && query::build_tenant::archived == *archived; // Note that there is no error reported if the filter parameters parsing // fails. Instead, it is considered that no packages match such a query. @@ -226,13 +235,13 @@ package_query (const brep::params::builds& params, // Package name. // if (!params.name ().empty ()) - q = q && P::id.name.like ( + q = q && qp::id.name.like ( package_name (transform (params.name ()), package_name::raw_string)); // Package version. // if (!params.version ().empty () && params.version () != "*") - q = q && compare_version_eq (P::id.version, + q = q && compare_version_eq (qp::id.version, version (params.version ()), // May throw. true); } @@ -344,9 +353,9 @@ handle (request& rq, response& rs) toolchains r; for (auto& t: build_db_->query ( - (tn ? query::id.package.tenant == *tn : query (true)) + - "ORDER BY" + query::toolchain_name + - order_by_version_desc (query::id.toolchain_version, false))) + (tn ? query::build::id.package.tenant == *tn : query (true)) + + "ORDER BY" + query::build::toolchain_name + + order_by_version_desc (query::build::id.toolchain_version, false))) r.emplace_back (move (t.name), move (t.version)); return r; @@ -440,7 +449,8 @@ handle (request& rq, response& rs) transaction t (build_db_->begin ()); count = build_db_->query_value ( - build_query (*build_conf_names_, params, tn)); + build_query ( + *build_conf_names_, params, tn, nullopt /* archived */)); // Print the filter form. // @@ -455,7 +465,8 @@ handle (request& rq, response& rs) // s << DIV; for (auto& pb: build_db_->query ( - build_query (*build_conf_names_, params, tn) + + build_query ( + *build_conf_names_, params, tn, nullopt /* archived */) + "ORDER BY" + query::build::timestamp + "DESC" + "OFFSET" + to_string (page * page_configs) + "LIMIT" + to_string (page_configs))) @@ -608,12 +619,12 @@ handle (request& rq, response& rs) size_t nmax ( config_toolchains.size () * build_db_->query_value ( - package_query (params, tn))); + package_query ( + params, tn, false /* archived */))); size_t ncur = build_db_->query_value ( - build_query (*build_conf_names_, - bld_params, - tn)); + build_query ( + *build_conf_names_, bld_params, tn, false /* archived */)); // From now we will be using specific package name and version for each // build database query. @@ -645,7 +656,8 @@ handle (request& rq, response& rs) // build_query (cstrings () /* configs */, bld_params, - nullopt /* tenant */)); + nullopt /* tenant */, + false /* archived */)); prep_bld_query bld_prep_query ( build_db_->prepare_query ( @@ -658,9 +670,9 @@ handle (request& rq, response& rs) // caching will not be easy as the cached values depend on the filter // form parameters. // - using query = query; - query q (package_query (params, - tn)); + query q ( + package_query ( + params, tn, false /* archived */)); for (const auto& p: build_db_->query (q)) { @@ -715,7 +727,8 @@ handle (request& rq, response& rs) using pkg_query = query; using prep_pkg_query = prepared_query; - pkg_query pq (package_query (params, tn)); + pkg_query pq ( + package_query (params, tn, false /* archived */)); // Specify the portion. Note that we will still be querying packages in // chunks, not to hold locks for too long. @@ -753,7 +766,8 @@ handle (request& rq, response& rs) // build_query (*build_conf_names_, bld_params, - nullopt /* tenant */)); + nullopt /* tenant */, + false /* archived */)); prep_bld_query bld_prep_query ( conn->prepare_query ("mod-builds-build-query", bq)); @@ -767,7 +781,8 @@ handle (request& rq, response& rs) using prep_ctr_query = prepared_query; ctr_query cq ( - package_id_eq (ctr_query::id, id)); + package_id_eq ( + ctr_query::build_package::id, id)); prep_ctr_query ctr_prep_query ( conn->prepare_query ( -- cgit v1.1