From 7b058820f5cd34666b389de28afe3a11f451f742 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 27 Oct 2014 14:36:00 +0100 Subject: only update unread per article count if its bigger than the current one --- service/feedservice.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'service') diff --git a/service/feedservice.php b/service/feedservice.php index 6ecf543b1..4ee7cb92d 100644 --- a/service/feedservice.php +++ b/service/feedservice.php @@ -109,9 +109,10 @@ class FeedService extends Service { } catch(DoesNotExistException $ex){} // insert feed + $itemCount = count($items); $feed->setFolderId($folderId); $feed->setUserId($userId); - $feed->setArticlesPerUpdate(count($items)); + $feed->setArticlesPerUpdate($itemCount); if ($title) { $feed->setTitle($title); @@ -122,7 +123,7 @@ class FeedService extends Service { // insert items in reverse order because the first one is usually // the newest item $unreadCount = 0; - for($i=count($items)-1; $i>=0; $i--){ + for($i=$itemCount-1; $i>=0; $i--){ $item = $items[$i]; $item->setFeedId($feed->getId()); @@ -205,16 +206,24 @@ class FeedService extends Service { } // update number of articles on every feed update - if($existingFeed->getArticlesPerUpdate() !== count($items)) { - $existingFeed->setArticlesPerUpdate(count($items)); + $itemCount = count($items); + + // this is needed to adjust to updates that add more items + // than when the feed was created. You can't update the count + // if it's lower because it may be due to the caching headers + // that were sent as the request and it might cause unwanted + // deletion and reappearing of feeds + if ($itemCount > $existingFeed->getArticlesPerUpdate()) { + $existingFeed->setArticlesPerUpdate($itemCount); } + $existingFeed->setLastModified($fetchedFeed->getLastModified()); $existingFeed->setEtag($fetchedFeed->getEtag()); $this->feedMapper->update($existingFeed); // insert items in reverse order because the first one is // usually the newest item - for($i=count($items)-1; $i>=0; $i--){ + for($i=$itemCount-1; $i>=0; $i--){ $item = $items[$i]; $item->setFeedId($existingFeed->getId()); -- cgit v1.2.3