From dda579ccaac67b5f360af98926a1697389bdbc6c Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 13 Sep 2013 17:59:16 +0200 Subject: also store feeds per article when doing updates --- CHANGELOG | 3 +- appinfo/database.xml | 7 ++++ appinfo/info.xml | 2 +- appinfo/version | 2 +- businesslayer/feedbusinesslayer.php | 8 +++-- db/feed.php | 2 ++ tests/unit/businesslayer/FeedBusinessLayerTest.php | 40 ++++++++++++++++++++++ 7 files changed, 59 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e1471bb7a..f99bb2000 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,8 @@ owncloud-news (1.601) * Remove Google Reader import * Replace Google Reader import with export and import of unread and starred articles -* Set default autoPurgeLimit to 5000. People who update will have to adjust this if they want to +* Autopurge limit is now added to the number of articles each feed gets when it updates +* Fix CORS headers for OPTIONS request deeper than one level owncloud-news (1.404) * Fix bug on postgres databases that would not delete old articles diff --git a/appinfo/database.xml b/appinfo/database.xml index 7d3cf2378..9b04e9c84 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -113,6 +113,13 @@ false true + + articles_per_update + integer + 0 + true + true + deleted_at integer diff --git a/appinfo/info.xml b/appinfo/info.xml index 15ddf6ee5..c6f87d3d6 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,6 +5,6 @@ An RSS/Atom feed reader. Requires the App Framework app and backgroundjobs need to be enabled. See the README.rst in the apps top directory AGPL Alessandro Cosentino, Bernhard Posselt, Jan-Christoph Borchardt. Powered by SimplePie (Ryan Parman, Geoffrey Sneddon, Ryan McCue and contributors). - 1.404 + 1.405 5.0.6 diff --git a/appinfo/version b/appinfo/version index 9539f398d..3e3adf552 100644 --- a/appinfo/version +++ b/appinfo/version @@ -1 +1 @@ -1.404 \ No newline at end of file +1.405 \ No newline at end of file diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php index fca4a0c74..e337e5785 100644 --- a/businesslayer/feedbusinesslayer.php +++ b/businesslayer/feedbusinesslayer.php @@ -104,6 +104,7 @@ class FeedBusinessLayer extends BusinessLayer { // insert feed $feed->setFolderId($folderId); $feed->setUserId($userId); + $feed->setArticlesPerUpdate(count($items)); $feed = $this->mapper->insert($feed); // insert items in reverse order because the first one is usually the @@ -175,8 +176,11 @@ class FeedBusinessLayer extends BusinessLayer { list($feed, $items) = $this->feedFetcher->fetch( $existingFeed->getUrl(), false); - // keep the current faviconLink - $feed->setFaviconLink($existingFeed->getFaviconLink()); + // update number of articles on every feed update + if($existingFeed->getArticlesPerUpdate() !== count($items)) { + $existingFeed->setArticlesPerUpdate(count($items)); + $this->mapper->update($existingFeed); + } // insert items in reverse order because the first one is usually // the newest item diff --git a/db/feed.php b/db/feed.php index e84e4489d..5e5bfcf5d 100644 --- a/db/feed.php +++ b/db/feed.php @@ -41,6 +41,7 @@ class Feed extends Entity implements IAPI { public $link; public $preventUpdate; public $deletedAt; + public $articlesPerUpdate; public function __construct(){ $this->addType('parentId', 'int'); @@ -49,6 +50,7 @@ class Feed extends Entity implements IAPI { $this->addType('unreadCount', 'int'); $this->addType('preventUpdate', 'bool'); $this->addType('deletedAt', 'int'); + $this->addType('articlesPerUpdate', 'int'); } diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 17222c57b..550f37dcb 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -173,6 +173,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->assertEquals($feed->getFolderId(), $folderId); $this->assertEquals($feed->getUrl(), $url); + $this->assertEquals($feed->getArticlesPerUpdate(), 2); } @@ -240,6 +241,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $feed = new Feed(); $feed->setId(3); $feed->getUrl('test'); + $feed->setArticlesPerUpdate(1); $feed->setUrlHash('yo'); $item = new Item(); @@ -286,6 +288,43 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->assertEquals($return, $feed); } + + public function testUpdateUpdatesArticlesPerFeedCount() { + $feed = new Feed(); + $feed->setId(3); + $feed->getUrl('test'); + $feed->setUrlHash('yo'); + + $existingFeed = new Feed(); + $feed->setArticlesPerUpdate(2); + + $item = new Item(); + $item->setGuidHash(md5('hi')); + $item->setFeedId(3); + $items = array( + $item + ); + + $ex = new DoesNotExistException('hi'); + + $fetchReturn = array($feed, $items); + + $this->feedMapper->expects($this->any()) + ->method('find') + ->will($this->returnValue($existingFeed)); + + $this->fetcher->expects($this->once()) + ->method('fetch') + ->will($this->returnValue(array($feed, $items))); + + $this->feedMapper->expects($this->once()) + ->method('update') + ->with($this->equalTo($existingFeed)); + + + $this->feedBusinessLayer->update($feed->getId(), $this->user); + } + public function testUpdateFails(){ $feed = new Feed(); $feed->setId(3); @@ -336,6 +375,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $feed = new Feed(); $feed->setId(3); $feed->getUrl('test'); + $feed->setArticlesPerUpdate(1); $item = new Item(); $item->setGuidHash(md5('hi')); -- cgit v1.2.3