diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-05-22 17:52:21 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-05-22 17:52:21 +0100 |
commit | 4e3fddb5b660be7e4646fd44cab817e4309253ae (patch) | |
tree | 9df0b0515a1382c2fe0474192400a003fe6e8981 | |
parent | Add support for merging dependencies (diff) | |
download | gentoobrowse-api-4e3fddb5b660be7e4646fd44cab817e4309253ae.tar.bz2 gentoobrowse-api-4e3fddb5b660be7e4646fd44cab817e4309253ae.tar.xz gentoobrowse-api-4e3fddb5b660be7e4646fd44cab817e4309253ae.zip |
Create file processors per run maintenance run
-rw-r--r-- | gentoobrowse-api/service/maintenanceimpl.cpp | 60 | ||||
-rw-r--r-- | gentoobrowse-api/service/maintenanceimpl.h | 20 |
2 files changed, 46 insertions, 34 deletions
diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp index 0957dda..bbece65 100644 --- a/gentoobrowse-api/service/maintenanceimpl.cpp +++ b/gentoobrowse-api/service/maintenanceimpl.cpp @@ -51,58 +51,62 @@ namespace Gentoo { { } + template<typename T> + Maintenance::FileProcessorPtr + Maintenance::createFileProessor() + { + return FileProcessorPtr(new T()); + } + Maintenance::Maintenance(IceTray::DatabasePoolPtr d) : IceTray::AbstractDatabaseClient(d) { - fps[CategoryMetaProcessor::FILETYPEID] = new CategoryMetaProcessor(); - fps[PackageManifestProcessor::FILETYPEID] = new PackageManifestProcessor(); - fps[PackageMetaProcessor::FILETYPEID] = new PackageMetaProcessor(); - fps[EbuildMetaProcessor::FILETYPEID] = new EbuildMetaProcessor(); - fps[UseGlobalProcessor::FILETYPEID] = new UseGlobalProcessor(); - fps[UseLocalProcessor::FILETYPEID] = new UseLocalProcessor(); - fps[UseGroupProcessor::FILETYPEID] = new UseGroupProcessor(); - fps[MasksProcessor::FILETYPEID] = new MasksProcessor(); + fpfs[CategoryMetaProcessor::FILETYPEID] = &createFileProessor<CategoryMetaProcessor>; + fpfs[PackageManifestProcessor::FILETYPEID] = &createFileProessor<PackageManifestProcessor>; + fpfs[PackageMetaProcessor::FILETYPEID] = &createFileProessor<PackageMetaProcessor>; + fpfs[EbuildMetaProcessor::FILETYPEID] = &createFileProessor<EbuildMetaProcessor>; + fpfs[UseGlobalProcessor::FILETYPEID] = &createFileProessor<UseGlobalProcessor>; + fpfs[UseLocalProcessor::FILETYPEID] = &createFileProessor<UseLocalProcessor>; + fpfs[UseGroupProcessor::FILETYPEID] = &createFileProessor<UseGroupProcessor>; + fpfs[MasksProcessor::FILETYPEID] = &createFileProessor<MasksProcessor>; } Maintenance::~Maintenance() { - for(const auto & fp : fps) { - delete fp.second; - } } void - Maintenance::fileDeleted(DB::Connection * dbc, const boost::filesystem::path & tmp, DB::SelectCommandPtr s) + Maintenance::fileDeleted(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s) { // b.filename, b.filesize, b.filetypeid, b.moddate, b.pathparts, b.repoid - s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this](auto fn, auto, auto ft, auto, auto, auto) { - this->fileHandle(ft, boost::bind(&FileProcessor::deleted, _1, dbc, fn)); + s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto) { + this->fileHandle(ft, fps, boost::bind(&FileProcessor::deleted, _1, dbc, fn)); }); } void - Maintenance::fileChanged(DB::Connection * dbc, const boost::filesystem::path & tmp, DB::SelectCommandPtr s) + Maintenance::fileChanged(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s) { // a.filename, a.repoid, a.filesize old_filesize, a.filetypeid old_filetypeid, a.moddate old_moddate, a.pathparts old_pathparts, b.filesize new_filesize, b.filetypeid new_filetypeid, b.moddate new_moddate, b.pathparts new_pathparts - s->forEachRow<std::string, int64_t, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t, int64_t, boost::posix_time::ptime, std::string>([dbc,&tmp,this](auto fn, auto, auto, auto ft, auto, auto, auto, auto, auto, auto) { - this->fileHandle(ft, boost::bind(&FileProcessor::modified, _1, dbc, fn, tmp / fn)); + s->forEachRow<std::string, int64_t, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t, int64_t, boost::posix_time::ptime, std::string>([dbc,&tmp,this,fps](auto fn, auto, auto, auto ft, auto, auto, auto, auto, auto, auto) { + this->fileHandle(ft, fps, boost::bind(&FileProcessor::modified, _1, dbc, fn, tmp / fn)); }); } void - Maintenance::fileCreated(DB::Connection * dbc, const boost::filesystem::path & tmp, DB::SelectCommandPtr s) + Maintenance::fileCreated(DB::Connection * dbc, const FileProcessors * fps, const boost::filesystem::path & tmp, DB::SelectCommandPtr s) { // b.filename, b.filesize, b.filetypeid, b.moddate, b.pathparts, b.repoid - s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this](auto fn, auto, auto ft, auto, auto, auto) { - this->fileHandle(ft, boost::bind(&FileProcessor::created, _1, dbc, fn, tmp / fn)); + s->forEachRow<std::string, int64_t, int64_t, boost::posix_time::ptime, std::string, int64_t>([dbc,&tmp,this,fps](auto fn, auto, auto ft, auto, auto, auto) { + this->fileHandle(ft, fps, boost::bind(&FileProcessor::created, _1, dbc, fn, tmp / fn)); }); } void - Maintenance::fileHandle(int64_t ft, const FileHandleFunc & f) const + Maintenance::fileHandle(int64_t ft, const FileProcessors * fps, const FileHandleFunc & f) const { - auto i = fps.find(ft); - if (i != fps.end()) { + auto i = fps->find(ft); + if (i != fps->end()) { f(i->second); } } @@ -131,15 +135,19 @@ namespace Gentoo { void Maintenance::processChanges(DB::Connection * dbc, const boost::filesystem::path & tmp) { + FileProcessors fps; + for (const auto & fpf : fpfs) { + fps[fpf.first] = fpf.second(); + } DB::StaticSqlWriter src(sql::maintenance::fileList.getSql()); DB::TablePatch tp; tp.srcExpr = &src; tp.dest = "gentoobrowse.files"; tp.pk = {"repoid", "filename"}; tp.cols = {"repoid", "filename", "filetypeid", "pathparts", "filesize", "moddate"}; - tp.beforeDelete = boost::bind(&Maintenance::fileDeleted, this, dbc, tmp, _1); - tp.beforeUpdate = boost::bind(&Maintenance::fileChanged, this, dbc, tmp, _1); - tp.beforeInsert = boost::bind(&Maintenance::fileCreated, this, dbc, tmp, _1); + tp.beforeDelete = boost::bind(&Maintenance::fileDeleted, this, dbc, &fps, tmp, _1); + tp.beforeUpdate = boost::bind(&Maintenance::fileChanged, this, dbc, &fps, tmp, _1); + tp.beforeInsert = boost::bind(&Maintenance::fileCreated, this, dbc, &fps, tmp, _1); DB::StaticSqlWriter obpo("processOrder NULLS LAST"); tp.order = &obpo; dbc->patchTable(&tp); diff --git a/gentoobrowse-api/service/maintenanceimpl.h b/gentoobrowse-api/service/maintenanceimpl.h index 846507b..378cbd1 100644 --- a/gentoobrowse-api/service/maintenanceimpl.h +++ b/gentoobrowse-api/service/maintenanceimpl.h @@ -19,9 +19,11 @@ namespace Gentoo { virtual void modified(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; virtual void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const; }; + typedef boost::shared_ptr<const FileProcessor> FileProcessorPtr; - typedef std::map<int64_t, const FileProcessor *> FileProcessors; - typedef boost::function<void(const FileProcessor *)> FileHandleFunc; + typedef std::map<int64_t, boost::function<FileProcessorPtr()>> FileProcessorFactories; + typedef std::map<int64_t, FileProcessorPtr> FileProcessors; + typedef boost::function<void(FileProcessorPtr)> FileHandleFunc; Maintenance(IceTray::DatabasePoolPtr d); ~Maintenance(); @@ -31,12 +33,14 @@ namespace Gentoo { private: static void createTempFileList(DB::Connection *, const boost::filesystem::path &); void processChanges(DB::Connection *, const boost::filesystem::path &); - void fileDeleted(DB::Connection * dbc, const boost::filesystem::path &, DB::SelectCommandPtr s); - void fileChanged(DB::Connection * dbc, const boost::filesystem::path &, DB::SelectCommandPtr s); - void fileCreated(DB::Connection * dbc, const boost::filesystem::path & tmp, DB::SelectCommandPtr s); - void fileHandle(int64_t filetypeId, const FileHandleFunc &) const; - - FileProcessors fps; + void fileDeleted(DB::Connection * dbc, const FileProcessors *, const boost::filesystem::path &, DB::SelectCommandPtr s); + void fileChanged(DB::Connection * dbc, const FileProcessors *, const boost::filesystem::path &, DB::SelectCommandPtr s); + void fileCreated(DB::Connection * dbc, const FileProcessors *, const boost::filesystem::path & tmp, DB::SelectCommandPtr s); + void fileHandle(int64_t filetypeId, const FileProcessors *, const FileHandleFunc &) const; + + template <typename T> + static FileProcessorPtr createFileProessor(); + FileProcessorFactories fpfs; }; } } |