From 798e75bf0f7bfd7fd4f38d3537a4ef3b7bb52876 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 3 Jun 2016 02:18:24 +0100 Subject: Bulk merge ebuild archs --- .../service/maintenance/ebuildMetaProcessor.cpp | 31 ++++++++++++++++------ .../service/maintenance/ebuildMetaProcessor.h | 1 + .../service/sql/maintenance/ebuildArchsInsert.sql | 2 ++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 gentoobrowse-api/service/sql/maintenance/ebuildArchsInsert.sql diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp index 65bc7bd..a57c674 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace U = Gentoo::Utils; using namespace Gentoo::Utils::File; @@ -116,6 +117,11 @@ namespace Gentoo { { "use", "text" }, }); useInsert = dbc->modify(sql::maintenance::ebuildUsesInsert.getSql()); + Utils::Database::namedTemp(dbc, "tmpEbuildArchs", { + { "ebuildId", "int" }, + { "arch", "text" }, + }); + archInsert = dbc->modify(sql::maintenance::ebuildArchsInsert.getSql()); } void @@ -150,6 +156,16 @@ namespace Gentoo { t.where = &ewf; dbc->patchTable(&t); } + { + dbc->execute("CREATE INDEX idxTmpEbuildArchs ON tmpEbuildArchs(ebuildId)"); + DB::TablePatch t; + t.src = "tmpEbuildArchs"; + t.dest = "gentoobrowse.ebuild_archs"; + t.pk = { "ebuildid", "arch" }; + t.cols = { "ebuildid", "arch" }; + t.where = &ewf; + dbc->patchTable(&t); + } } if (!catsDeleteFrom.empty()) { bool any = false; @@ -171,6 +187,7 @@ namespace Gentoo { { Utils::Database::drop(dbc, "tmpEbuildDeps"); Utils::Database::drop(dbc, "tmpEbuildUses"); + Utils::Database::drop(dbc, "tmpEbuildArchs"); } void @@ -178,20 +195,17 @@ namespace Gentoo { { U::EntityWhereFilter ewf("ebuildId", ebuildId); // IUSE - DB::TablePatch 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"; - t.srcExpr = &sep_keywords; - t.pk = { "ebuildid", "arch" }; - t.cols = { "ebuildid", "arch" }; - t.where = &ewf; - dbc->patchTable(&t); + if (auto keywords = ecp.get("KEYWORDS")) { + archInsert->bindParamI(0, ebuildId); + archInsert->bindParamS(1, *keywords); + archInsert->execute(); + } // Dependencies ebuildIds.insert(ebuildId); depInsert->bindParamI(1, ebuildId); @@ -204,6 +218,7 @@ namespace Gentoo { insertDeps(Portage::Utils::Depend::parse(rdepend->first, rdepend->second)); } if (newest) { + DB::TablePatch t; // HOMEPAGE U::EntityWhereFilter pwf("packageId", packageId); U::SplitEbuildProps sep_homepage("packageId", packageId, "url", ecp.get("HOMEPAGE")); diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h index 7b3e088..f4d4b07 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h @@ -28,6 +28,7 @@ namespace Gentoo { DB::ModifyCommandPtr depInsert; DB::ModifyCommandPtr useInsert; + DB::ModifyCommandPtr archInsert; std::set ebuildIds; std::set catsDeleteFrom; }; diff --git a/gentoobrowse-api/service/sql/maintenance/ebuildArchsInsert.sql b/gentoobrowse-api/service/sql/maintenance/ebuildArchsInsert.sql new file mode 100644 index 0000000..7ea8eae --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/ebuildArchsInsert.sql @@ -0,0 +1,2 @@ +INSERT INTO tmpEbuildArchs(ebuildId, arch) +SELECT DISTINCT ?::INT, REGEXP_SPLIT_TO_TABLE(?, '\s+') -- cgit v1.2.3