diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-05-24 22:11:40 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-05-24 22:11:40 +0100 |
commit | 2261ee5bf498adb95d9139f508180d045bcb0e15 (patch) | |
tree | eb16af46dbf326cff1194dea65735a133babcfde | |
parent | Extend EntityWhereFilter to operate on a set of Ids (diff) | |
download | gentoobrowse-api-2261ee5bf498adb95d9139f508180d045bcb0e15.tar.bz2 gentoobrowse-api-2261ee5bf498adb95d9139f508180d045bcb0e15.tar.xz gentoobrowse-api-2261ee5bf498adb95d9139f508180d045bcb0e15.zip |
Bulk merge ebuild dependencies (accidentally fixes bug where dependencies weren't found if a package didn't yet exist)
5 files changed, 76 insertions, 35 deletions
diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp index 230a00f..2ba14e7 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp @@ -22,6 +22,7 @@ #include <sql/maintenance/ebuildUpdate.sql.h> #include <sql/maintenance/ebuildDelete.sql.h> #include <sql/maintenance/ebuildDeps.sql.h> +#include <sql/maintenance/ebuildRDeps.sql.h> namespace U = Gentoo::Utils; using namespace Gentoo::Utils::File; @@ -97,6 +98,49 @@ namespace Gentoo { } void + EbuildMetaProcessor::prepare(DB::Connection * dbc) + { + depInsert = Utils::Database::namedTemp(dbc, "tmpEbuildDeps", { + { "ebuildId", "int" }, // 1 + { "runtime", "boolean" }, // 5 + { "category", "text" }, // 0 + { "package", "text" }, // 4 + { "version", "text" }, // 7 + { "slot", "text" }, // 6 + { "flags", "text" }, // 2 + { "op", "text" } // 3 + }).second; + } + + 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; + + 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); + } + } + + void + EbuildMetaProcessor::tidy(DB::Connection * dbc) + { + Utils::Database::drop(dbc, "tmpEbuildDeps"); + } + + void EbuildMetaProcessor::perEbuildUpdates(DB::Connection * dbc, const U::EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId) { U::EntityWhereFilter ewf("ebuildId", ebuildId); @@ -118,31 +162,12 @@ namespace Gentoo { t.where = &ewf; dbc->patchTable(&t); // Dependencies - t.pk = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; - t.cols = { "ebuildid", "packageid", "versionspec", "flags", "slot", "op" }; - t.where = &ewf; - DB::StaticSqlWriter s(sql::maintenance::ebuildDeps.getSql()); - t.srcExpr = &s; - auto ins = Utils::Database::namedTemp(dbc, "tmpEbuildDeps", { - { "ebuildId", "int" }, // 1 - { "category", "text" }, // 0 - { "package", "text" }, // 4 - { "version", "text" }, // 6 - { "slot", "text" }, // 5 - { "flags", "text" }, // 2 - { "op", "text" } // 3 - }); - ins.second->bindParamI(1, ebuildId); - auto db = Portage::Utils::Depend::parse(ecp.get("DEPEND").value_or("")); - t.dest = "gentoobrowse.ebuild_deps"; - insertDeps(ins.second.get(), db); - dbc->patchTable(&t); - dbc->execute("TRUNCATE TABLE tmpEbuildDeps"); - auto dr = Portage::Utils::Depend::parse(ecp.get("RDEPEND").value_or("")); - t.dest = "gentoobrowse.ebuild_rdeps"; - insertDeps(ins.second.get(), dr); - dbc->patchTable(&t); - Utils::Database::drop(dbc, "tmpEbuildDeps"); + ebuildIds.insert(ebuildId); + depInsert->bindParamI(1, ebuildId); + depInsert->bindParamB(5, false); + insertDeps(Portage::Utils::Depend::parse(ecp.get("DEPEND").value_or(""))); + depInsert->bindParamB(5, true); + insertDeps(Portage::Utils::Depend::parse(ecp.get("RDEPEND").value_or(""))); if (newest) { // HOMEPAGE U::EntityWhereFilter pwf("packageId", packageId); @@ -168,16 +193,16 @@ namespace Gentoo { } void - EbuildMetaProcessor::insertDeps(DB::ModifyCommand * ins, const std::vector<Gentoo::DependencyPtr> & deps) + EbuildMetaProcessor::insertDeps(const std::vector<Gentoo::DependencyPtr> & deps) { for (const auto & d : deps) { - ins->bindParamS(0, d->category); - ins->bindParamS(2, boost::algorithm::join(d->use, ",")); - ins->bindParamS(3, d->op |= std::string()); - ins->bindParamS(4, d->package); - ins->bindParamS(5, d->slot |= std::string()); - ins->bindParamS(6, d->version |= std::string()); - ins->execute(); + depInsert->bindParamS(0, d->category); + depInsert->bindParamS(2, boost::algorithm::join(d->use, ",")); + depInsert->bindParamS(3, d->op |= std::string()); + depInsert->bindParamS(4, d->package); + depInsert->bindParamS(6, d->slot |= std::string()); + depInsert->bindParamS(7, d->version |= std::string()); + depInsert->execute(); } } diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h index 51daad0..a337e8b 100644 --- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h +++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.h @@ -19,8 +19,15 @@ namespace Gentoo { void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) override; private: + void prepare(DB::Connection * dbc) override; + void apply(DB::Connection * dbc) override; + void tidy(DB::Connection * dbc) override; + void perEbuildUpdates(DB::Connection * dbc, const Utils::EbuildCacheParser & ecp, int64_t ebuildId, bool newest, int64_t packageId); - void insertDeps(DB::ModifyCommand * dbc, const std::vector<Gentoo::DependencyPtr> &); + void insertDeps(const std::vector<Gentoo::DependencyPtr> &); + + DB::ModifyCommandPtr depInsert; + std::set<int64_t> ebuildIds; }; } } diff --git a/gentoobrowse-api/service/sql/maintenance/ebuildDeps.sql b/gentoobrowse-api/service/sql/maintenance/ebuildDeps.sql index 801c877..ae33b65 100644 --- a/gentoobrowse-api/service/sql/maintenance/ebuildDeps.sql +++ b/gentoobrowse-api/service/sql/maintenance/ebuildDeps.sql @@ -4,4 +4,5 @@ WHERE c.categoryid = p.categoryid AND c.name = e.category AND p.name = e.package + AND e.runtime = false ) diff --git a/gentoobrowse-api/service/sql/maintenance/ebuildRDeps.sql b/gentoobrowse-api/service/sql/maintenance/ebuildRDeps.sql new file mode 100644 index 0000000..b0e54b9 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/ebuildRDeps.sql @@ -0,0 +1,8 @@ +( + SELECT DISTINCT ebuildid, packageid, e.version versionspec, flags, slot, op + FROM gentoobrowse.categories c, gentoobrowse.packages p, tmpEbuildDeps e + WHERE c.categoryid = p.categoryid + AND c.name = e.category + AND p.name = e.package + AND e.runtime = true +) diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index cef7554..8be95a1 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) insRepo->execute(); doRefreshPackageTree(sd, db, "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d", "gentoo", - m, 2084, 5, 1, 482, 981, 3626, 4593, 501, 393, 238, 50, 1573, 1323, 1059); + m, 2084, 5, 1, 482, 981, 3626, 4593, 501, 393, 238, 50, 1573, 2008, 1543); db->execute("COPY gentoobrowse.categories TO '/tmp/categories1.tsv'"); db->execute("COPY gentoobrowse.packages TO '/tmp/packages1.tsv'"); |