From 599bd6335c27ff2c1a48cc0b3a5ee115d49afcda Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 12 Jul 2019 20:37:45 +0300 Subject: Speed-up builds page loading --- libbrep/build-package.hxx | 2 +- libbrep/build.hxx | 6 +++++- libbrep/build.xml | 8 ++++++++ mod/mod-builds.cxx | 27 +++++++++++++++------------ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx index c491b9e..c288f07 100644 --- a/libbrep/build-package.hxx +++ b/libbrep/build-package.hxx @@ -71,7 +71,7 @@ namespace brep // Foreign object that is mapped to a subset of the package object. // - #pragma db object table("build_package") pointer(shared_ptr) readonly + #pragma db object table("build_package") pointer(shared_ptr) readonly session class build_package { public: diff --git a/libbrep/build.hxx b/libbrep/build.hxx index ea51c00..a8139a8 100644 --- a/libbrep/build.hxx +++ b/libbrep/build.hxx @@ -26,7 +26,7 @@ // #define LIBBREP_BUILD_SCHEMA_VERSION_BASE 7 -#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 8, closed) +#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 9, closed) // We have to keep these mappings at the global scope instead of inside // the brep namespace because they need to be also effective in the @@ -242,6 +242,10 @@ namespace brep #pragma db member(toolchain_version) \ set(this.toolchain_version.init (this.id.toolchain_version, (?))) + // Speed-up queries with ordering the result by the timestamp. + // + #pragma db member(timestamp) index + #pragma db member(results) id_column("") value_column("") \ section(results_section) diff --git a/libbrep/build.xml b/libbrep/build.xml index 032fd38..2a621b6 100644 --- a/libbrep/build.xml +++ b/libbrep/build.xml @@ -1,4 +1,12 @@ + + + + + + + + diff --git a/mod/mod-builds.cxx b/mod/mod-builds.cxx index 30a18a6..dedabfe 100644 --- a/mod/mod-builds.cxx +++ b/mod/mod-builds.cxx @@ -494,13 +494,17 @@ handle (request& rq, response& rs) // Specify the portion. Note that we will be querying builds in chunks, // not to hold locks for too long. // + // Also note that for each build we also load the corresponding + // package. Nevertheless, we use a fairly large portion to speed-up the + // builds traversal but also cache the package objects (see below). + // size_t offset (0); // Print package build configurations ordered by the timestamp (later goes // first). // q += "ORDER BY" + query::build::timestamp + "DESC" + - "OFFSET" + query::_ref (offset) + "LIMIT 50"; + "OFFSET" + query::_ref (offset) + "LIMIT 500"; connection_ptr conn (build_db_->connection ()); @@ -515,11 +519,12 @@ handle (request& rq, response& rs) size_t skip (page * page_configs); size_t print (page_configs); - // Note that adjacent builds may well relate to the same package. We will - // use this fact for a cheap optimization, loading the build package only - // if it differs from the previous one. + // Cache the build package objects that would otherwise be loaded multiple + // times for different configuration/toolchain combinations. Note that the + // build package is a subset of the package object and normally has a + // small memory footprint. // - shared_ptr p; + session sn; for (bool ne (true); ne; ) { @@ -541,18 +546,15 @@ handle (request& rq, response& rs) { shared_ptr& b (pb.build); - // Prior to loading the package object check if it is already - // loaded. - // - if (p == nullptr || p->id != b->id.package) - p = build_db_->load (b->id.package); - auto i (build_conf_map_->find (b->configuration.c_str ())); assert (i != build_conf_map_->end ()); // Match the configuration against the package build // expressions/constraints. // + shared_ptr p ( + build_db_->load (b->id.package)); + if (!exclude (p->builds, p->constraints, *i->second)) { if (skip != 0) @@ -846,7 +848,8 @@ handle (request& rq, response& rs) 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. + // chunks, not to hold locks for too long. For each package we will query + // its builds, so let's keep the portion small. // size_t offset (0); -- cgit v1.1