From 0d3d6d032d4780fcb62c3e5ec51c401cc1a8c478 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 3 Jun 2016 01:55:05 +0100 Subject: Bulk merge ebuild use flags --- .../service/maintenance/ebuildMetaProcessor.cpp | 56 ++++++++++++++-------- .../service/maintenance/ebuildMetaProcessor.h | 1 + .../service/sql/maintenance/ebuildUsesInsert.sql | 2 + 3 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 gentoobrowse-api/service/sql/maintenance/ebuildUsesInsert.sql diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp index c8d52a3..65bc7bd 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace U = Gentoo::Utils; using namespace Gentoo::Utils::File; @@ -110,27 +111,45 @@ namespace Gentoo { { "flags", "text" }, // 2 { "op", "text" } // 3 }).second; + Utils::Database::namedTemp(dbc, "tmpEbuildUses", { + { "ebuildId", "int" }, + { "use", "text" }, + }); + useInsert = dbc->modify(sql::maintenance::ebuildUsesInsert.getSql()); } void EbuildMetaProcessor::apply(DB::Connection * dbc) { if (!ebuildIds.empty()) { - DB::TablePatch t; - t.pk = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; - t.cols = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; U::EntityWhereFilter ewf("ebuildId", ebuildIds); - t.where = &ewf; + { + dbc->execute("CREATE INDEX idxTmpEbuildDeps ON tmpEbuildDeps(ebuildId, runtime)"); + DB::TablePatch t; + t.pk = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; + t.cols = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; + t.where = &ewf; - DB::StaticSqlWriter sb(sql::maintenance::ebuildDeps.getSql()); - t.srcExpr = &sb; - t.dest = "gentoobrowse.ebuild_deps"; - dbc->patchTable(&t); + DB::StaticSqlWriter sb(sql::maintenance::ebuildDeps.getSql()); + t.srcExpr = &sb; + t.dest = "gentoobrowse.ebuild_deps"; + dbc->patchTable(&t); - DB::StaticSqlWriter sr(sql::maintenance::ebuildRDeps.getSql()); - t.srcExpr = &sr; - t.dest = "gentoobrowse.ebuild_rdeps"; - dbc->patchTable(&t); + DB::StaticSqlWriter sr(sql::maintenance::ebuildRDeps.getSql()); + t.srcExpr = &sr; + t.dest = "gentoobrowse.ebuild_rdeps"; + dbc->patchTable(&t); + } + { + dbc->execute("CREATE INDEX idxTmpEbuildUses ON tmpEbuildUses(ebuildId)"); + DB::TablePatch t; + t.src = "tmpEbuildUses"; + t.dest = "gentoobrowse.ebuild_uses"; + t.pk = { "ebuildid", "use" }; + t.cols = { "ebuildid", "use" }; + t.where = &ewf; + dbc->patchTable(&t); + } } if (!catsDeleteFrom.empty()) { bool any = false; @@ -151,6 +170,7 @@ namespace Gentoo { EbuildMetaProcessor::tidy(DB::Connection * dbc) { Utils::Database::drop(dbc, "tmpEbuildDeps"); + Utils::Database::drop(dbc, "tmpEbuildUses"); } void @@ -159,13 +179,11 @@ namespace Gentoo { U::EntityWhereFilter ewf("ebuildId", ebuildId); // IUSE DB::TablePatch t; - U::SplitEbuildProps sep_use("ebuildId", ebuildId, "use", ecp.get("IUSE")); - t.dest = "gentoobrowse.ebuild_uses"; - t.srcExpr = &sep_use; - t.pk = { "ebuildid", "use" }; - t.cols = { "ebuildid", "use" }; - t.where = &ewf; - dbc->patchTable(&t); + if (auto uses = ecp.get("IUSE")) { + useInsert->bindParamI(0, ebuildId); + useInsert->bindParamS(1, *uses); + useInsert->execute(); + } // KEYWORDS U::SplitEbuildProps sep_keywords("ebuildId", ebuildId, "arch", ecp.get("KEYWORDS")); t.dest = "gentoobrowse.ebuild_archs"; diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h index 2e92217..7b3e088 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h @@ -27,6 +27,7 @@ namespace Gentoo { void insertDeps(const std::vector &); DB::ModifyCommandPtr depInsert; + DB::ModifyCommandPtr useInsert; std::set ebuildIds; std::set catsDeleteFrom; }; diff --git a/gentoobrowse-api/service/sql/maintenance/ebuildUsesInsert.sql b/gentoobrowse-api/service/sql/maintenance/ebuildUsesInsert.sql new file mode 100644 index 0000000..9d01c96 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/ebuildUsesInsert.sql @@ -0,0 +1,2 @@ +INSERT INTO tmpEbuildUses(ebuildId, use) +SELECT DISTINCT ?::INT, TRIM(REGEXP_SPLIT_TO_TABLE(?, '\s+'), '+') -- cgit v1.2.3