From 5ba14279e8a537fb9d6186d18ec6c42a7b41e5b3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 15 Dec 2016 16:50:50 +0000 Subject: Fix the phased application of file changes which turned out to be nonsense of the highest order. --- .../service/maintenancePackageTree.cpp | 56 ++++++++++++++++------ 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/gentoobrowse-api/service/maintenancePackageTree.cpp b/gentoobrowse-api/service/maintenancePackageTree.cpp index d31b267..8f8bc6b 100644 --- a/gentoobrowse-api/service/maintenancePackageTree.cpp +++ b/gentoobrowse-api/service/maintenancePackageTree.cpp @@ -169,6 +169,22 @@ R"DATA( 10 category metadata 2 2 {"(2,metadata.xml)"} Utils::Database::drop(dbc, p.src); } + class PhaseSourceFilter : public Utils::EntityWhereFilter { + public: + PhaseSourceFilter() : + Utils::EntityWhereFilter("filetypeId") + { + } + + void + writeSql(AdHoc::Buffer & sql) override + { + sql.append("( SELECT * FROM filelist a WHERE "); + Utils::EntityWhereFilter::writeSql(sql); + sql.append(")"); + } + }; + void Maintenance::processChanges(DB::Connection * dbc, const boost::filesystem::path & tmp, const RepoMap & repos) { @@ -181,21 +197,33 @@ R"DATA( 10 category metadata 2 2 {"(2,metadata.xml)"} } dbc->execute(sql::maintenance::fileListCreate.getSql()); dbc->execute(sql::maintenance::fileListCreatePk.getSql()); - for (int i = 1; i < 3; i +=1 ) { - DB::TablePatch tp; - tp.src = "filelist"; - tp.dest = "gentoobrowse.files"; - tp.pk = {"pathparts", "repoid"}; - tp.cols = {"pathparts", "repoid", "filetypeid", "filesize", "moddate"}; - tp.beforeDelete = boost::bind(&Maintenance::fileDeleted, this, dbc, &fps, tmp, &repos, _1); - tp.beforeUpdate = boost::bind(&Maintenance::fileChanged, this, dbc, &fps, tmp, &repos, _1); - tp.beforeInsert = boost::bind(&Maintenance::fileCreated, this, dbc, &fps, tmp, &repos, _1); - DB::StaticSqlWriter obpo("b.updateOrder NULLS LAST"); - tp.order = &obpo; + DB::TablePatch tp; + tp.dest = "gentoobrowse.files"; + tp.pk = {"pathparts", "repoid"}; + tp.cols = {"pathparts", "repoid", "filetypeid", "filesize", "moddate"}; + tp.beforeDelete = boost::bind(&Maintenance::fileDeleted, this, dbc, &fps, tmp, &repos, _1); + tp.beforeUpdate = boost::bind(&Maintenance::fileChanged, this, dbc, &fps, tmp, &repos, _1); + tp.beforeInsert = boost::bind(&Maintenance::fileCreated, this, dbc, &fps, tmp, &repos, _1); + DB::StaticSqlWriter obpo("b.updateOrder NULLS LAST"); + tp.order = &obpo; + auto phases = dbc->select("SELECT phase FROM gentoobrowse.filetypes GROUP BY phase ORDER BY phase"); + for (const auto & phase : phases->as()) { + Utils::EntityWhereFilter pf("filetypeId"); + PhaseSourceFilter psf; + auto getFts = dbc->select("SELECT filetypeId FROM gentoobrowse.filetypes WHERE phase = ?"); + getFts->bindParamI(0, phase.value<0>()); + for (const auto & ft : getFts->as()) { + pf.entityIds.insert(ft.value<0>()); + psf.entityIds.insert(ft.value<0>()); + } + tp.srcExpr = &psf; + tp.where = &pf; dbc->patchTable(&tp); - } - for (const auto & fp : fps) { - fp.second->apply(dbc); + for (const auto & fp : pf.entityIds) { + if (fps.find(fp) != fps.end()) { + fps[fp]->apply(dbc); + } + } } dbc->execute("DROP TABLE filelist"); dbc->execute("DROP TABLE filelistraw"); -- cgit v1.2.3