From ff99aea2a2156d158b5e922bafae3876a92c898c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 21 Dec 2015 05:03:44 +0000 Subject: Add methods for getting recent news and searching news. --- gentoobrowse-api/api/portage.ice | 2 ++ gentoobrowse-api/domain/portage-models.ice | 1 + gentoobrowse-api/service/portageimpl.cpp | 18 ++++++++++++++++-- gentoobrowse-api/service/portageimpl.h | 2 ++ gentoobrowse-api/service/sql/portage/getNewsRecent.sql | 4 ++++ gentoobrowse-api/service/sql/portage/getNewsSearch.sql | 4 ++++ gentoobrowse-api/unittests/testPortage.cpp | 18 ++++++++++++++++++ 7 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gentoobrowse-api/service/sql/portage/getNewsRecent.sql create mode 100644 gentoobrowse-api/service/sql/portage/getNewsSearch.sql diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 7e1eb43..9479eff 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -21,6 +21,8 @@ module Gentoo { idempotent SearchResultBugs getBugsSearch(string query); idempotent NewsItem getNewsItem(string newsid); + idempotent News getNewsSearch(string query); + idempotent News getNewsRecent(int items); }; }; diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index b5a75c9..ca018e8 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -84,6 +84,7 @@ module Gentoo { sequence Ebuilds; sequence Bugs; sequence ChangeLog; + sequence News; }; #endif diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index b199934..408d467 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include Portage::Portage(AdHoc::ResourcePool & d) : AbstractDatabaseClient(d) @@ -101,12 +103,24 @@ Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) Gentoo::SearchResultBugs Portage::getBugsSearch(const std::string & query, const Ice::Current &) { - return fetch(query, query); + return fetch(query, query); } Gentoo::NewsItemPtr Portage::getNewsItem(const std::string & id, const Ice::Current &) { - return fetch(id); + return fetch(id); +} + +Gentoo::News +Portage::getNewsSearch(const std::string & query, const Ice::Current &) +{ + return fetch(query); +} + +Gentoo::News +Portage::getNewsRecent(Ice::Int items, const Ice::Current &) +{ + return fetch(items); } diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 9588095..9a8246d 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -27,6 +27,8 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, AbstractDatabaseClient { Gentoo::SearchResultBugs getBugsSearch(const std::string & query, const Ice::Current &) override; Gentoo::NewsItemPtr getNewsItem(const std::string &, const Ice::Current &) override; + Gentoo::News getNewsSearch(const std::string &, const Ice::Current &) override; + Gentoo::News getNewsRecent(Ice::Int, const Ice::Current &) override; }; #endif diff --git a/gentoobrowse-api/service/sql/portage/getNewsRecent.sql b/gentoobrowse-api/service/sql/portage/getNewsRecent.sql new file mode 100644 index 0000000..a70c6b0 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getNewsRecent.sql @@ -0,0 +1,4 @@ +SELECT n.newsid, n.title, n.posted, n.authorname, n.authoremail, n.body, n.atomspec, n.urls +FROM gentoobrowse.news n +ORDER BY n.posted DESC, n.newsid +LIMIT ? diff --git a/gentoobrowse-api/service/sql/portage/getNewsSearch.sql b/gentoobrowse-api/service/sql/portage/getNewsSearch.sql new file mode 100644 index 0000000..b67ac99 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getNewsSearch.sql @@ -0,0 +1,4 @@ +SELECT n.newsid, n.title, n.posted, n.authorname, n.authoremail, n.body, n.atomspec, n.urls +FROM gentoobrowse.news n +WHERE gentoobrowse.newsfts(n) @@ plainto_tsquery(?) +ORDER BY n.posted DESC, n.newsid diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index c5c85f6..271ff34 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -241,6 +241,24 @@ BOOST_AUTO_TEST_CASE( getNewsItem ) BOOST_REQUIRE_EQUAL("http://ispras.linuxbase.org/index.php/ABI_compliance_checker", n2->urls.front()); } +BOOST_AUTO_TEST_CASE( getNewsSearch ) +{ + auto ns = p->getNewsSearch("gcc"); + BOOST_REQUIRE_EQUAL(5, ns.size()); + BOOST_REQUIRE_EQUAL("Or you might see linkage failures with \"std::__cxx11::string\" in the output.", ns.front()->body[1]); + BOOST_REQUIRE_EQUAL("These are signs that you need to rebuild packages using the new C++ ABI. You can quickly do so by using revdep-rebuild (from gentoolkit) like so: # revdep-rebuild --library 'libstdc\\+\\+\\.so\\.6' -- --exclude gcc", ns.front()->body[2]); + BOOST_REQUIRE_EQUAL("2015-10-22T00:00:00", ns.front()->posted); + BOOST_REQUIRE_EQUAL("2009-01-04T00:00:00", ns.back()->posted); +} + +BOOST_AUTO_TEST_CASE( getNewsRecent ) +{ + auto ns = p->getNewsRecent(3); + BOOST_REQUIRE_EQUAL(3, ns.size()); + BOOST_REQUIRE_EQUAL("2015-10-22T00:00:00", ns.front()->posted); + BOOST_REQUIRE_EQUAL("2015-10-07T00:00:00", ns.back()->posted); +} + BOOST_AUTO_TEST_CASE( cache ) { auto c1 = p->getCategory(311, Ice::Current()); -- cgit v1.2.3