diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-16 23:52:23 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-16 23:52:23 +0200 |
commit | cdbf8ca56d427b835ad675c92d57fe5a3140a2f5 (patch) | |
tree | 04367f8eda65cbc78de23ac830f693fe9cbca0ce /businesslayer/feedbusinesslayer.php | |
parent | e95c1af89093f74e2ba95864b99e3df63dc5dce1 (diff) |
dont add items if they are already in the database
Diffstat (limited to 'businesslayer/feedbusinesslayer.php')
-rw-r--r-- | businesslayer/feedbusinesslayer.php | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php index f7666fc1c..ec6d7283a 100644 --- a/businesslayer/feedbusinesslayer.php +++ b/businesslayer/feedbusinesslayer.php @@ -72,14 +72,25 @@ class FeedBusinessLayer extends BusinessLayer { // insert items in reverse order because the first one is usually the // newest item + $unreadCount = 0; for($i=count($items)-1; $i>=0; $i--){ $item = $items[$i]; $item->setFeedId($feed->getId()); - $this->itemMapper->insert($item); + + // check if item exists (guidhash is the same) + // and ignore it if it does + try { + $this->itemMapper->findByGuidHash( + $item->getGuidHash(), $item->getFeedId(), $userId); + continue; + } catch(DoesNotExistException $ex){ + $unreadCount += 1; + $this->itemMapper->insert($item); + } } // set unread count - $feed->setUnreadCount(count($items)); + $feed->setUnreadCount($unreadCount); return $feed; } catch(FetcherException $ex){ |