summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/service/maintenancePackageTree.cpp56
1 files 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<int64_t> {
+ public:
+ PhaseSourceFilter() :
+ Utils::EntityWhereFilter<int64_t>("filetypeId")
+ {
+ }
+
+ void
+ writeSql(AdHoc::Buffer & sql) override
+ {
+ sql.append("( SELECT * FROM filelist a WHERE ");
+ Utils::EntityWhereFilter<int64_t>::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<int64_t>()) {
+ Utils::EntityWhereFilter<int64_t> 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<int64_t>()) {
+ 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");