From 96f62a04f6e42ded0cf70c5c8c18bbafdd2470a1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 19 Sep 2016 20:52:05 +0100 Subject: Extends API with functions to support website --- gentoobrowse-api/api/portage.ice | 7 +++ gentoobrowse-api/domain/extended-models.ice | 3 + gentoobrowse-api/domain/portage-models.ice | 7 +++ gentoobrowse-api/service/portageimpl.cpp | 60 ++++++++++++++++++++ gentoobrowse-api/service/portageimpl.h | 7 +++ .../service/sql/portage/findCategory.sql | 3 + .../sql/portage/getAllOverviewCategories.sql | 6 ++ .../service/sql/portage/getAllPackages.sql | 3 + .../portage/getCategoriesWithRecentAdditions.sql | 11 ++++ .../sql/portage/getOverviewCategoriesInSuper.sql | 2 +- .../sql/portage/getPackagesWithRecentAdditions.sql | 10 ++++ gentoobrowse-api/service/sql/portage/getSyncs.sql | 5 ++ .../service/sql/portage/getTopTrackedPackages.sql | 6 ++ .../unittests/fixtures/user_packages.dat | 3 + gentoobrowse-api/unittests/fixtures/users.dat | 1 + gentoobrowse-api/unittests/testPortage.cpp | 65 ++++++++++++++++++++++ 16 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 gentoobrowse-api/service/sql/portage/findCategory.sql create mode 100644 gentoobrowse-api/service/sql/portage/getAllOverviewCategories.sql create mode 100644 gentoobrowse-api/service/sql/portage/getAllPackages.sql create mode 100644 gentoobrowse-api/service/sql/portage/getCategoriesWithRecentAdditions.sql create mode 100644 gentoobrowse-api/service/sql/portage/getPackagesWithRecentAdditions.sql create mode 100644 gentoobrowse-api/service/sql/portage/getSyncs.sql create mode 100644 gentoobrowse-api/service/sql/portage/getTopTrackedPackages.sql diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 9479eff..56d066b 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -4,17 +4,24 @@ module Gentoo { interface Portage { idempotent Category getCategory(int id); + idempotent Category findCategory(string name); idempotent Categories getAllCategories(); idempotent Categories getCategoriesInSuper(string super); + idempotent OverviewCategoriesBySuper getAllOverviewCategories(); idempotent OverviewCategories getOverviewCategoriesInSuper(string super); idempotent Package getPackage(int id); idempotent optional(0) Package findPackage(string category, string package); + idempotent Packages getAllPackages(); idempotent Packages getPackagesInCategory(int id); idempotent SearchResultPackages getPackagesSearch(string query); idempotent Ebuilds getPackageVersions(int id); idempotent ChangeLog getPackageChangeLog(int id); + idempotent Syncs getSyncs(int syncs); idempotent Ebuilds getRecentAdditions(int syncs); + idempotent Packages getPackagesWithRecentAdditions(int syncs); + idempotent Categories getCategoriesWithRecentAdditions(int syncs); + idempotent Packages getTopTrackedPackages(int n); idempotent Bug getBug(int id); idempotent Bugs getPackageBugs(int packageId); diff --git a/gentoobrowse-api/domain/extended-models.ice b/gentoobrowse-api/domain/extended-models.ice index cccd45a..f030361 100644 --- a/gentoobrowse-api/domain/extended-models.ice +++ b/gentoobrowse-api/domain/extended-models.ice @@ -6,6 +6,8 @@ module Gentoo { class OverviewCategory extends Category { int packagecount; + [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] + string lastaddition; }; class SearchResultPackage extends Package { @@ -19,6 +21,7 @@ module Gentoo { sequence SearchResultPackages; sequence SearchResultBugs; sequence OverviewCategories; + dictionary OverviewCategoriesBySuper; }; #endif diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index d15194e..dc4a57e 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -91,12 +91,19 @@ module Gentoo { StringList use; }; + struct Sync { + [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] + string timestamp; + int ebuilds; + }; + sequence Categories; sequence Packages; sequence Ebuilds; sequence Bugs; sequence ChangeLog; sequence News; + sequence Syncs; }; #endif diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index 1a5b96c..7653976 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -1,15 +1,22 @@ #include "portageimpl.h" #include +#include #include #include +#include #include +#include #include #include +#include #include #include #include #include +#include +#include #include +#include #include #include #include @@ -30,6 +37,12 @@ Portage::getCategory(Ice::Int id, const Ice::Current &) return fetchCache(sql::portage::getCategory, 30, id); } +Gentoo::CategoryPtr +Portage::findCategory(const std::string & name, const Ice::Current &) +{ + return fetchCache(sql::portage::findCategory, 30, name); +} + Gentoo::Categories Portage::getAllCategories(const Ice::Current &) { @@ -42,6 +55,23 @@ Portage::getCategoriesInSuper(const std::string & super, const Ice::Current &) return fetchCache(sql::portage::getCategoriesInSuper, 30, super); } +Gentoo::OverviewCategoriesBySuper +Portage::getAllOverviewCategories(const Ice::Current &) +{ + Gentoo::OverviewCategoriesBySuper rtn; + auto cats = fetchCache(sql::portage::getAllOverviewCategories, 30); + for (const auto & c : cats) { + auto hyphen = c->name.find('-'); + if (hyphen == (std::string::npos)-1) { + rtn[c->name].push_back(c); + } + else { + rtn[c->name.substr(0, hyphen)].push_back(c); + } + } + return rtn; +} + Gentoo::OverviewCategories Portage::getOverviewCategoriesInSuper(const std::string & super, const Ice::Current &) { @@ -60,6 +90,12 @@ Portage::findPackage(const std::string & cat, const std::string & pkg, const Ice return fetchCache>(sql::portage::findPackage, 30, cat, pkg); } +Gentoo::Packages +Portage::getAllPackages(const Ice::Current &) +{ + return fetchCache(sql::portage::getAllPackages, 30); +} + Gentoo::Packages Portage::getPackagesInCategory(Ice::Int id, const Ice::Current &) { @@ -84,12 +120,36 @@ Portage::getPackageChangeLog(Ice::Int id, const Ice::Current &) return fetchCache(sql::portage::getPackageChangeLog, 30, id); } +Gentoo::Syncs +Portage::getSyncs(Ice::Int syncs, const Ice::Current &) +{ + return fetchCache(sql::portage::getSyncs, 30, syncs); +} + Gentoo::Ebuilds Portage::getRecentAdditions(Ice::Int syncs, const Ice::Current &) { return fetchCache(sql::portage::getRecentAdditions, 30, syncs); } +Gentoo::Packages +Portage::getPackagesWithRecentAdditions(Ice::Int syncs, const Ice::Current &) +{ + return fetchCache(sql::portage::getPackagesWithRecentAdditions, 30, syncs); +} + +Gentoo::Packages +Portage::getTopTrackedPackages(Ice::Int n, const Ice::Current &) +{ + return fetchCache(sql::portage::getTopTrackedPackages, 30, n); +} + +Gentoo::Categories +Portage::getCategoriesWithRecentAdditions(Ice::Int syncs, const Ice::Current &) +{ + return fetchCache(sql::portage::getCategoriesWithRecentAdditions, 30, syncs); +} + Gentoo::BugPtr Portage::getBug(Ice::Int id, const Ice::Current &) { diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index d47941b..273fbed 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -12,17 +12,24 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab Portage(boost::shared_ptr> d); Gentoo::CategoryPtr getCategory(Ice::Int id, const Ice::Current &) override; + Gentoo::CategoryPtr findCategory(const std::string & name, const Ice::Current &) override; Gentoo::Categories getAllCategories(const Ice::Current &) override; Gentoo::Categories getCategoriesInSuper(const std::string &, const Ice::Current &) override; + Gentoo::OverviewCategoriesBySuper getAllOverviewCategories(const Ice::Current &) override; Gentoo::OverviewCategories getOverviewCategoriesInSuper(const std::string &, const Ice::Current &) override; Gentoo::PackagePtr getPackage(Ice::Int id, const Ice::Current &) override; IceUtil::Optional findPackage(const std::string &, const std::string &, const Ice::Current &) override; Gentoo::Packages getPackagesInCategory(Ice::Int id, const Ice::Current &) override; + Gentoo::Packages getAllPackages(const Ice::Current &) override; Gentoo::SearchResultPackages getPackagesSearch(const std::string & query, const Ice::Current &) override; Gentoo::Ebuilds getPackageVersions(Ice::Int id, const Ice::Current &) override; Gentoo::ChangeLog getPackageChangeLog(Ice::Int id, const Ice::Current &) override; + Gentoo::Syncs getSyncs(Ice::Int syncs, const Ice::Current &) override; Gentoo::Ebuilds getRecentAdditions(Ice::Int syncs, const Ice::Current &) override; + Gentoo::Packages getPackagesWithRecentAdditions(Ice::Int syncs, const Ice::Current &) override; + Gentoo::Categories getCategoriesWithRecentAdditions(Ice::Int syncs, const Ice::Current &) override; + Gentoo::Packages getTopTrackedPackages(Ice::Int n, const Ice::Current &) override; Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; diff --git a/gentoobrowse-api/service/sql/portage/findCategory.sql b/gentoobrowse-api/service/sql/portage/findCategory.sql new file mode 100644 index 0000000..b1cb130 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/findCategory.sql @@ -0,0 +1,3 @@ +SELECT c.categoryid, c.name, c.summary +FROM gentoobrowse.categories c +WHERE c.name = ? diff --git a/gentoobrowse-api/service/sql/portage/getAllOverviewCategories.sql b/gentoobrowse-api/service/sql/portage/getAllOverviewCategories.sql new file mode 100644 index 0000000..d4b72c8 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getAllOverviewCategories.sql @@ -0,0 +1,6 @@ +SELECT c.categoryid, c.name, c.summary, COUNT(p.packageid) packagecount, MAX(p.firstseen) lastaddition +FROM gentoobrowse.categories c + LEFT OUTER JOIN gentoobrowse.packages p + ON p.categoryid = c.categoryid +GROUP BY c.categoryid +ORDER BY c.name diff --git a/gentoobrowse-api/service/sql/portage/getAllPackages.sql b/gentoobrowse-api/service/sql/portage/getAllPackages.sql new file mode 100644 index 0000000..fc8fe6d --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getAllPackages.sql @@ -0,0 +1,3 @@ +SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.firstseen, p.maintainer, p.maintainername, p.herd +FROM gentoobrowse.packages p +ORDER BY p.categoryid, p.name diff --git a/gentoobrowse-api/service/sql/portage/getCategoriesWithRecentAdditions.sql b/gentoobrowse-api/service/sql/portage/getCategoriesWithRecentAdditions.sql new file mode 100644 index 0000000..4007bf2 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getCategoriesWithRecentAdditions.sql @@ -0,0 +1,11 @@ +SELECT c.categoryid, c.name, c.summary +FROM gentoobrowse.categories c, gentoobrowse.packages p, gentoobrowse.ebuilds e +WHERE c.categoryid = p.categoryid +AND p.packageid = e.packageid +AND e.firstseen IN ( + SELECT DISTINCT s.firstseen + FROM gentoobrowse.ebuilds s + ORDER BY s.firstseen DESC + LIMIT ?) +GROUP BY c.categoryid +ORDER BY c.categoryid diff --git a/gentoobrowse-api/service/sql/portage/getOverviewCategoriesInSuper.sql b/gentoobrowse-api/service/sql/portage/getOverviewCategoriesInSuper.sql index e971aed..876e551 100644 --- a/gentoobrowse-api/service/sql/portage/getOverviewCategoriesInSuper.sql +++ b/gentoobrowse-api/service/sql/portage/getOverviewCategoriesInSuper.sql @@ -1,4 +1,4 @@ -SELECT c.categoryid, c.name, c.summary, COUNT(p.packageid) packagecount +SELECT c.categoryid, c.name, c.summary, COUNT(p.packageid) packagecount, MAX(p.firstseen) lastaddition FROM gentoobrowse.categories c LEFT OUTER JOIN gentoobrowse.packages p ON p.categoryid = c.categoryid diff --git a/gentoobrowse-api/service/sql/portage/getPackagesWithRecentAdditions.sql b/gentoobrowse-api/service/sql/portage/getPackagesWithRecentAdditions.sql new file mode 100644 index 0000000..052da8d --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getPackagesWithRecentAdditions.sql @@ -0,0 +1,10 @@ +SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.firstseen, p.maintainer, p.maintainername, p.herd +FROM gentoobrowse.packages p, gentoobrowse.ebuilds e +WHERE p.packageid = e.packageid +AND e.firstseen IN ( + SELECT DISTINCT s.firstseen + FROM gentoobrowse.ebuilds s + ORDER BY s.firstseen DESC + LIMIT ?) +GROUP BY p.packageid +ORDER BY p.packageid diff --git a/gentoobrowse-api/service/sql/portage/getSyncs.sql b/gentoobrowse-api/service/sql/portage/getSyncs.sql new file mode 100644 index 0000000..eef5e3e --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getSyncs.sql @@ -0,0 +1,5 @@ +SELECT s.firstseen AS timestamp, COUNT(*) AS ebuilds +FROM gentoobrowse.ebuilds s +GROUP BY s.firstseen +ORDER BY s.firstseen DESC +LIMIT ? diff --git a/gentoobrowse-api/service/sql/portage/getTopTrackedPackages.sql b/gentoobrowse-api/service/sql/portage/getTopTrackedPackages.sql new file mode 100644 index 0000000..c328d73 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getTopTrackedPackages.sql @@ -0,0 +1,6 @@ +SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.firstseen, p.maintainer, p.maintainername, p.herd +FROM gentoobrowse.packages p, gentoobrowse.user_packages up +WHERE p.packageid = up.packageid +GROUP BY p.packageid +ORDER BY COUNT(*) DESC +LIMIT ? diff --git a/gentoobrowse-api/unittests/fixtures/user_packages.dat b/gentoobrowse-api/unittests/fixtures/user_packages.dat index e69de29..2a87d43 100644 --- a/gentoobrowse-api/unittests/fixtures/user_packages.dat +++ b/gentoobrowse-api/unittests/fixtures/user_packages.dat @@ -0,0 +1,3 @@ +1 49517 2010-08-12 15:50:47.72758 +1 54144 2014-12-10 23:00:13.500634 +1 55943 2013-07-29 22:47:58.538607 diff --git a/gentoobrowse-api/unittests/fixtures/users.dat b/gentoobrowse-api/unittests/fixtures/users.dat index e69de29..4544513 100644 --- a/gentoobrowse-api/unittests/fixtures/users.dat +++ b/gentoobrowse-api/unittests/fixtures/users.dat @@ -0,0 +1 @@ +1 randomdan Dan Goodliffe p@55w0rd dan@randomdan.homeip.net \N diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 90ad707..2a8dd77 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -22,6 +22,16 @@ BOOST_AUTO_TEST_CASE( getCategory ) BOOST_REQUIRE_EQUAL(169, cat->summary->length()); } +BOOST_AUTO_TEST_CASE( findCategory ) +{ + auto cat = p->findCategory("app-backup"); + BOOST_REQUIRE(cat); + BOOST_REQUIRE_EQUAL(316, cat->categoryid); + BOOST_REQUIRE_EQUAL("app-backup", cat->name); + BOOST_REQUIRE(cat->summary); + BOOST_REQUIRE_EQUAL(169, cat->summary->length()); +} + BOOST_AUTO_TEST_CASE( getAllCategories ) { auto cats = p->getAllCategories(); @@ -44,12 +54,43 @@ BOOST_AUTO_TEST_CASE( getCategoriesInSuper ) BOOST_REQUIRE_EQUAL(0, cats.size()); } +BOOST_AUTO_TEST_CASE( getSyncs ) +{ + auto syncs = p->getSyncs(3); + BOOST_REQUIRE_EQUAL(3, syncs.size()); + BOOST_REQUIRE_EQUAL("2015-12-07T15:01:06.742996", syncs.front().timestamp); + BOOST_REQUIRE_EQUAL(3, syncs.front().ebuilds); + BOOST_REQUIRE_EQUAL("2015-11-29T15:00:49.856355", syncs.back().timestamp); + BOOST_REQUIRE_EQUAL(3, syncs.back().ebuilds); +} + +BOOST_AUTO_TEST_CASE( getCategoriesWithRecentAdditions ) +{ + auto cats = p->getCategoriesWithRecentAdditions(3); + BOOST_REQUIRE_EQUAL(4, cats.size()); + BOOST_REQUIRE_EQUAL("dev-vcs", cats.front()->name); + BOOST_REQUIRE_EQUAL("app-backup", cats.back()->name); +} + +BOOST_AUTO_TEST_CASE( getAllOverviewCategories ) +{ + auto cats = p->getAllOverviewCategories(); + BOOST_REQUIRE_EQUAL(3, cats.size()); + BOOST_REQUIRE_EQUAL("app", cats.begin()->first); + BOOST_REQUIRE_EQUAL(2, cats["app"].size()); + BOOST_REQUIRE_EQUAL("app-backup", cats["app"].front()->name); + BOOST_REQUIRE_EQUAL("app-crypt", cats["app"].back()->name); + BOOST_REQUIRE_EQUAL("2015-12-02T19:12:59.916989", cats["app"].back()->lastaddition); + BOOST_REQUIRE_EQUAL("net", cats.rbegin()->first); +} + BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper ) { auto cats = p->getOverviewCategoriesInSuper("dev"); BOOST_REQUIRE_EQUAL(2, cats.size()); BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name); BOOST_REQUIRE_EQUAL("dev-vcs", cats.back()->name); + BOOST_REQUIRE_EQUAL("2015-08-24T20:20:23.209651", cats.back()->lastaddition); BOOST_REQUIRE_EQUAL(136, cats.front()->packagecount); BOOST_REQUIRE_EQUAL(88, cats.back()->packagecount); cats = p->getOverviewCategoriesInSuper("net"); @@ -90,6 +131,14 @@ BOOST_AUTO_TEST_CASE( findPackageMissing ) BOOST_REQUIRE_EQUAL(53258, (*pkg)->packageid); } +BOOST_AUTO_TEST_CASE( getAllPackages ) +{ + auto pkgs = p->getAllPackages(); + BOOST_REQUIRE_EQUAL(444, pkgs.size()); + BOOST_REQUIRE_EQUAL("archway", pkgs.front()->name); + BOOST_REQUIRE_EQUAL("vzdump", pkgs.back()->name); +} + BOOST_AUTO_TEST_CASE( getPackagesInCategory ) { auto pkgs = p->getPackagesInCategory(311); @@ -98,6 +147,22 @@ BOOST_AUTO_TEST_CASE( getPackagesInCategory ) BOOST_REQUIRE_EQUAL("veracity", pkgs.back()->name); } +BOOST_AUTO_TEST_CASE( getPackagesWithRecentAdditions ) +{ + auto pkgs = p->getPackagesWithRecentAdditions(3); + BOOST_REQUIRE_EQUAL(8, pkgs.size()); + BOOST_REQUIRE_EQUAL("mercurial", pkgs.front()->name); + BOOST_REQUIRE_EQUAL("letsencrypt", pkgs.back()->name); +} + +BOOST_AUTO_TEST_CASE( getPackagesPopular ) +{ + auto pkgs = p->getTopTrackedPackages(3); + BOOST_REQUIRE_EQUAL(3, pkgs.size()); + BOOST_REQUIRE_EQUAL("squid", pkgs.front()->name); + BOOST_REQUIRE_EQUAL("subversion", pkgs.back()->name); +} + BOOST_AUTO_TEST_CASE( searchEmpty ) { auto matches = p->getPackagesSearch(""); -- cgit v1.2.3