diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-15 16:50:50 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-16 16:14:15 +0000 | 
| commit | 93e4670fef71575a1ea4afd66a09c6b75422cdc2 (patch) | |
| tree | 7e0ba1230211aa1135a3e2ac215e1002c14d2781 | |
| parent | Dump DB before doing assertions so you have some hope of diagnosing problems (diff) | |
| download | gentoobrowse-api-93e4670fef71575a1ea4afd66a09c6b75422cdc2.tar.bz2 gentoobrowse-api-93e4670fef71575a1ea4afd66a09c6b75422cdc2.tar.xz gentoobrowse-api-93e4670fef71575a1ea4afd66a09c6b75422cdc2.zip | |
Fix the phased application of file changes which turned out to be nonsense of the highest order.
| -rw-r--r-- | gentoobrowse-api/service/maintenancePackageTree.cpp | 56 | 
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"); | 
