diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-21 00:18:15 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-25 21:27:48 +0100 |
commit | 8f8c83cba2d58f0b465dc0a105ede7ebc36e64ef (patch) | |
tree | 3d2c4a30224d58a8a84c604f902c2028fdbfd666 | |
parent | Move category maint SQL to .sql files (diff) | |
download | gentoobrowse-api-8f8c83cba2d58f0b465dc0a105ede7ebc36e64ef.tar.bz2 gentoobrowse-api-8f8c83cba2d58f0b465dc0a105ede7ebc36e64ef.tar.xz gentoobrowse-api-8f8c83cba2d58f0b465dc0a105ede7ebc36e64ef.zip |
Ingest package declarations from manifests
6 files changed, 79 insertions, 0 deletions
diff --git a/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp b/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp new file mode 100644 index 0000000..8d6147c --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageManifestProcessor.cpp @@ -0,0 +1,33 @@ +#include "packageManifestProcessor.h" +#include <modifycommand.h> +#include "fileUtils.h" +#include <sql/maintenance/packageInsert.sql.h> +#include <sql/maintenance/packageDelete.sql.h> + +using namespace Gentoo::Utils::File; + +namespace Gentoo { + namespace Service { + const int PackageManifestProcessor::FILETYPEID = 8; + + void + PackageManifestProcessor::created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path &) const + { + auto m = dbc->modify(sql::maintenance::packageInsert::sql); + m->bindParamS(0, (fn / 2).string()); + m->bindParamS(1, fn.parent_path().string()); + m->bindParamS(2, (fn / 1).string()); + m->execute(); + } + + void + PackageManifestProcessor::deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const + { + auto m = dbc->modify(sql::maintenance::packageDelete::sql); + m->bindParamS(0, (fn / 2).string()); + m->bindParamS(1, (fn / 1).string()); + m->execute(); + } + } +} + diff --git a/gentoobrowse-api/service/maintenance/packageManifestProcessor.h b/gentoobrowse-api/service/maintenance/packageManifestProcessor.h new file mode 100644 index 0000000..f7347b2 --- /dev/null +++ b/gentoobrowse-api/service/maintenance/packageManifestProcessor.h @@ -0,0 +1,22 @@ +#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMANIFESTPROC_H +#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_PACKAGEMANIFESTPROC_H + +#include "../maintenanceimpl.h" +#include <connection.h> +#include <modifycommand.h> +#include <boost/filesystem/path.hpp> + +namespace Gentoo { + namespace Service { + class PackageManifestProcessor : public Maintenance::FileProcessor { + public: + static const int FILETYPEID; + + void created(DB::Connection * dbc, const boost::filesystem::path & fn, const boost::filesystem::path & path) const; + void deleted(DB::Connection * dbc, const boost::filesystem::path & fn) const; + }; + } +} + +#endif + diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp index 9b8b550..d8b85ef 100644 --- a/gentoobrowse-api/service/maintenanceimpl.cpp +++ b/gentoobrowse-api/service/maintenanceimpl.cpp @@ -7,6 +7,7 @@ #include <sql/maintenance/createTempFileListTable.sql.h> #include <sql/maintenance/createTempFileListView.sql.h> #include "maintenance/categoryMetaProcessor.h" +#include "maintenance/packageManifestProcessor.h" /* 1 package metadata {"(1,metadata)","(2,md5-cache)"} @@ -47,6 +48,7 @@ namespace Gentoo { IceTray::AbstractDatabaseClient(d) { fps[CategoryMetaProcessor::FILETYPEID] = new CategoryMetaProcessor(); + fps[PackageManifestProcessor::FILETYPEID] = new PackageManifestProcessor(); } Maintenance::~Maintenance() diff --git a/gentoobrowse-api/service/sql/maintenance/packageDelete.sql b/gentoobrowse-api/service/sql/maintenance/packageDelete.sql new file mode 100644 index 0000000..5a2a0f1 --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/packageDelete.sql @@ -0,0 +1,4 @@ +DELETE FROM gentoobrowse.packages p +USING gentoobrowse.categories c +WHERE p.name = ? +AND c.name = ? diff --git a/gentoobrowse-api/service/sql/maintenance/packageInsert.sql b/gentoobrowse-api/service/sql/maintenance/packageInsert.sql new file mode 100644 index 0000000..223cdbe --- /dev/null +++ b/gentoobrowse-api/service/sql/maintenance/packageInsert.sql @@ -0,0 +1,4 @@ +INSERT INTO gentoobrowse.packages(categoryid, name, description) +SELECT c.categoryid, ?, ? +FROM gentoobrowse.categories c +WHERE c.name = ? diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp index b8bb5d4..2b3a4ba 100644 --- a/gentoobrowse-api/unittests/testMaintenance.cpp +++ b/gentoobrowse-api/unittests/testMaintenance.cpp @@ -58,12 +58,26 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree ) SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.files", int64_t, 2084); SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories", int64_t, 5); SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories WHERE name = 'dev-vcs'", int64_t, 1); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.packages", int64_t, 478); + db->execute("COPY gentoobrowse.categories TO '/tmp/categories1.tsv'"); + db->execute("COPY gentoobrowse.packages TO '/tmp/packages1.tsv'"); sd.extract("756569aa764177340726dd3d40b41d89b11b20c7", "gentoo"); m->refreshPackageTree(); sd.clean(); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.files", int64_t, 2034); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories", int64_t, 5); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories WHERE name = 'dev-vcs'", int64_t, 1); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.packages", int64_t, 480); + db->execute("COPY gentoobrowse.categories TO '/tmp/categories2.tsv'"); + db->execute("COPY gentoobrowse.packages TO '/tmp/packages2.tsv'"); + m->refreshPackageTree(); + + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.files", int64_t, 0); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.categories", int64_t, 0); + SQL_REQUIRE_EQUAL("SELECT COUNT(*) FROM gentoobrowse.packages", int64_t, 0); } BOOST_AUTO_TEST_SUITE_END(); |