From f9691e0faf7e3844aece1ebedc22805bd5782ba2 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Fri, 13 Sep 2013 18:14:40 +0200 Subject: respect articles per update count in item cleanup --- README.rst | 2 +- db/itemmapper.php | 11 +++++++---- tests/unit/db/ItemMapperTest.php | 22 ++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 5e8c7c0c7..6faef2947 100644 --- a/README.rst +++ b/README.rst @@ -173,7 +173,7 @@ The configuration is in **INI** format and looks like this: * **autoPurgeMinimumInterval**: Minimum amount of seconds after deleted feeds and folders are removed from the database. -* **autoPurgeCount**: To let people have more read and unstarred items per feed before they are deleted increase this value. If you set this too low this will cause read articles to reappear: For instance a feed offers the newest 100 entries. The user reads 80 of them, the autoPrugeCount is set to 20. After the cleanup which runs with the update only 20 read entries of that feed will remain, which means 60 entries are deleted. The next update will then readd those 60 entries because they are gone from the database and thus appear to be new entries. +* **autoPurgeCount**: Defines the minimum amount of articles that can be unread per feed before they get deleted * **simplePieCacheDuration**: Amount of seconds to cache feeds * **feedFetcherTimeout**: Maximum number of seconds to wait for an RSS or Atom feed to load. If a feed takes longer than that number of seconds to update, the update will be aborted * **useCronUpdates**: To use a custom update/cron script you need to disable the cronjob which is run by ownCloud by default by setting this to false diff --git a/db/itemmapper.php b/db/itemmapper.php index 8fa40e8eb..891cb624d 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -258,10 +258,13 @@ class ItemMapper extends Mapper implements IMapper { */ public function deleteReadOlderThanThreshold($threshold){ $status = StatusFlag::STARRED | StatusFlag::UNREAD; - $sql = 'SELECT COUNT(*) `size`, `feed_id` ' . - 'FROM `*PREFIX*news_items` ' . - 'WHERE NOT ((`status` & ?) > 0) ' . - 'GROUP BY `feed_id` ' . + $sql = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' . + '`items`.`feed_id` AS `feed_id`, ' . + 'FROM `*PREFIX*news_items` `items` ' . + 'JOIN `*PREFIX*news_feeds` `feeds` ' . + 'ON `feeds`.`id` = `items`.`feed_id` ' . + 'WHERE NOT ((`items`.`status` & ?) > 0) ' . + 'GROUP BY `items`.`feed_id` ' . 'HAVING COUNT(*) > ?'; $params = array($status, $threshold); $result = $this->execute($sql, $params); diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index ae045ce31..bba3e143e 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -325,10 +325,13 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { public function testDeleteReadOlderThanThresholdDoesNotDeleteBelowThreshold(){ $status = StatusFlag::STARRED | StatusFlag::UNREAD; - $sql = 'SELECT COUNT(*) `size`, `feed_id` ' . - 'FROM `*PREFIX*news_items` ' . - 'WHERE NOT ((`status` & ?) > 0) ' . - 'GROUP BY `feed_id` ' . + $sql = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' . + '`items`.`feed_id` AS `feed_id`, ' . + 'FROM `*PREFIX*news_items` `items` ' . + 'JOIN `*PREFIX*news_feeds` `feeds` ' . + 'ON `feeds`.`id` = `items`.`feed_id` ' . + 'WHERE NOT ((`items`.`status` & ?) > 0) ' . + 'GROUP BY `items`.`feed_id` ' . 'HAVING COUNT(*) > ?'; $threshold = 10; @@ -346,10 +349,13 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility { $threshold = 10; $status = StatusFlag::STARRED | StatusFlag::UNREAD; - $sql1 = 'SELECT COUNT(*) `size`, `feed_id` ' . - 'FROM `*PREFIX*news_items` ' . - 'WHERE NOT ((`status` & ?) > 0) ' . - 'GROUP BY `feed_id` ' . + $sql1 = 'SELECT COUNT(*) - `feeds`.`articles_per_update` AS `size`, ' . + '`items`.`feed_id` AS `feed_id`, ' . + 'FROM `*PREFIX*news_items` `items` ' . + 'JOIN `*PREFIX*news_feeds` `feeds` ' . + 'ON `feeds`.`id` = `items`.`feed_id` ' . + 'WHERE NOT ((`items`.`status` & ?) > 0) ' . + 'GROUP BY `items`.`feed_id` ' . 'HAVING COUNT(*) > ?'; $params1 = array($status, $threshold); -- cgit v1.2.3