Skip to content

Commit

Permalink
DB: Don't show deleted feed items
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Mar 23, 2021
1 parent 4e1d6ea commit 69efb75
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
3 changes: 3 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* [Thomas Müller](mailto:thomas.mueller@tmit.eu)
* [Hoàng Đức Hiếu](mailto:hdhoang@zahe.me)
* [Daniel Opitz](mailto:git@copynpaste.de)
* [Marco Nassabain](mailto:marco.nassabain@hotmail.com)
* [Sean Molenaar](mailto:sean@m2mobi.com)
* [rakekniven](mailto:mark.ziegler@rakekniven.de)
* [David-Development](mailto:david-dev@live.de)
Expand All @@ -25,6 +26,7 @@
* [Lukas Reschke](mailto:lukas@owncloud.com)
* [Bart Visscher](mailto:bartv@thisnet.nl)
* [Christian Elmer](mailto:christian@keinkurt.de)
* [Jimmy Huynh](mailto:jimmy.huynh@etu.unistra.fr)
* [Thomas Tanghus](mailto:thomas@tanghus.net)
* [Volkan Gezer](mailto:volkangezer@gmail.com)
* [Xéfir Destiny](mailto:xefir@crystalyx.net)
Expand All @@ -47,6 +49,7 @@
* [Gioele Falcetti](mailto:thegio.f@gmail.com)
* [Igor Bubelov](mailto:igor@bubelov.com)
* [Jan C. Borchardt](mailto:hey@jancborchardt.net)
* [Jimmy Huynh](mailto:linkatox@gmail.com)
* [John Kristensen](mailto:john@jerrykan.com)
* [Keunes](mailto:11229646+keunes@users.noreply.github.com)
* [Konrad Graefe](mailto:konradgraefe@aol.com)
Expand Down
6 changes: 6 additions & 0 deletions lib/Db/ItemMapperV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public function findAllInFeedAfter(
->andWhere('items.last_modified >= :updatedSince')
->andWhere('feeds.user_id = :userId')
->andWhere('feeds.id = :feedId')
->andWhere('feeds.deleted_at = 0')
->setParameters([
'updatedSince' => $updatedSince,
'feedId' => $feedId,
Expand Down Expand Up @@ -353,6 +354,7 @@ public function findAllInFolderAfter(
->innerJoin('feeds', FolderMapperV2::TABLE_NAME, 'folders', 'feeds.folder_id = folders.id')
->andWhere('items.last_modified >= :updatedSince')
->andWhere('feeds.user_id = :userId')
->andWhere('feeds.deleted_at = 0')
->andWhere('folders.id = :folderId')
->setParameters(['updatedSince' => $updatedSince, 'folderId' => $folderId, 'userId' => $userId])
->orderBy('items.last_modified', 'DESC')
Expand Down Expand Up @@ -381,6 +383,7 @@ public function findAllAfter(string $userId, int $feedType, int $updatedSince):
->from($this->tableName, 'items')
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->andWhere('items.last_modified >= :updatedSince')
->andWhere('feeds.deleted_at = 0')
->andWhere('feeds.user_id = :userId')
->setParameters(['updatedSince' => $updatedSince, 'userId' => $userId])
->orderBy('items.last_modified', 'DESC')
Expand Down Expand Up @@ -443,6 +446,7 @@ public function findAllFeed(
$builder->select('items.*')
->from($this->tableName, 'items')
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->andWhere('feeds.deleted_at = 0')
->andWhere('feeds.user_id = :userId')
->andWhere('items.feed_id = :feedId')
->setParameter('userId', $userId)
Expand Down Expand Up @@ -503,6 +507,7 @@ public function findAllFolder(
->from($this->tableName, 'items')
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->andWhere('feeds.user_id = :userId')
->andWhere('feeds.deleted_at = 0')
->andWhere($folderWhere)
->setParameter('userId', $userId)
->setMaxResults($limit)
Expand Down Expand Up @@ -554,6 +559,7 @@ public function findAllItems(
->from($this->tableName, 'items')
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->andWhere('feeds.user_id = :userId')
->andWhere('feeds.deleted_at = 0')
->setParameter('userId', $userId)
->setMaxResults($limit)
->orderBy('items.last_modified', ($oldestFirst ? 'ASC' : 'DESC'))
Expand Down
28 changes: 18 additions & 10 deletions tests/Unit/Db/ItemMapperAfterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ public function testFindAllInFeedAfter()
->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id')
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.user_id = :userId'],
['feeds.id = :feedId']
['feeds.id = :feedId'],
['feeds.deleted_at = 0']
)
->will($this->returnSelf());

Expand Down Expand Up @@ -142,12 +143,13 @@ public function testFindAllInFeedAfterHideRead()
->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id')
->will($this->returnSelf());

$this->builder->expects($this->exactly(4))
$this->builder->expects($this->exactly(5))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.user_id = :userId'],
['feeds.id = :feedId'],
['feeds.deleted_at = 0'],
['items.unread = 1']
)
->will($this->returnSelf());
Expand Down Expand Up @@ -210,11 +212,12 @@ public function testFindAllInFolderAfter()
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['folders.id = :folderId']
)
->will($this->returnSelf());
Expand Down Expand Up @@ -277,11 +280,12 @@ public function testFindAllInFolderAfterHideRead()
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(4))
$this->builder->expects($this->exactly(5))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['folders.id = :folderId'],
['items.unread = 1']
)
Expand Down Expand Up @@ -342,10 +346,11 @@ public function testFindAllAfterUnread()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.unread = 1']
)
Expand Down Expand Up @@ -405,10 +410,11 @@ public function testFindAllAfterStarred()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.starred = 1']
)
Expand Down Expand Up @@ -468,10 +474,11 @@ public function testFindAllAfterAll()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.deleted_at = 0'],
['feeds.user_id = :userId']
)
->will($this->returnSelf());
Expand Down Expand Up @@ -533,10 +540,11 @@ public function testFindAllAfterInvalid()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('andWhere')
->withConsecutive(
['items.last_modified >= :updatedSince'],
['feeds.deleted_at = 0'],
['feeds.user_id = :userId']
)
->will($this->returnSelf());
Expand Down Expand Up @@ -574,4 +582,4 @@ public function testFindAllAfterInvalid()
$this->assertEquals([Item::fromRow(['id' => 4])], $result);
}

}
}
45 changes: 28 additions & 17 deletions tests/Unit/Db/ItemMapperPaginatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ public function testFindAllItemsInvalid()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId']
['feeds.user_id = :userId'],
['feeds.deleted_at = 0']
)
->will($this->returnSelf());

Expand Down Expand Up @@ -150,10 +151,11 @@ public function testFindAllItemsFullInverted()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['items.id > :offset']
)
->will($this->returnSelf());
Expand Down Expand Up @@ -221,10 +223,11 @@ public function testFindAllItemsUnread()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['items.id < :offset'],
['items.unread = 1']
)
Expand All @@ -235,13 +238,11 @@ public function testFindAllItemsUnread()
->withConsecutive(['userId', 'jack'], ['offset', 10])
->will($this->returnSelf());


$this->builder->expects($this->exactly(1))
->method('setMaxResults')
->with(10)
->will($this->returnSelf());


$this->builder->expects($this->exactly(0))
->method('setFirstResult')
->with(10)
Expand Down Expand Up @@ -293,10 +294,11 @@ public function testFindAllItemsStarred()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['items.id < :offset'],
['items.starred = 1']
)
Expand Down Expand Up @@ -367,10 +369,11 @@ public function testFindAllItemsStarredSearch()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(5))
$this->builder->expects($this->exactly(6))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['items.search_index LIKE :term0'],
['items.search_index LIKE :term1'],
['items.id < :offset'],
Expand Down Expand Up @@ -441,9 +444,10 @@ public function testFindAllFeed()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.feed_id = :feedId'],
['items.id < :offset']
Expand Down Expand Up @@ -513,9 +517,10 @@ public function testFindAllFeedInverted()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.feed_id = :feedId'],
['items.id > :offset']
Expand Down Expand Up @@ -583,9 +588,10 @@ public function testFindAllFeedHideRead()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(4))
$this->builder->expects($this->exactly(5))
->method('andWhere')
->withConsecutive(
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.feed_id = :feedId'],
['items.id < :offset'],
Expand Down Expand Up @@ -659,9 +665,10 @@ public function testFindAllFeedSearch()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(5))
$this->builder->expects($this->exactly(6))
->method('andWhere')
->withConsecutive(
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.feed_id = :feedId'],
['items.search_index LIKE :term0'],
Expand Down Expand Up @@ -751,10 +758,11 @@ public function testFindAllFolderIdNull()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['x IS NULL'],
['items.id < :offset']
)
Expand Down Expand Up @@ -835,10 +843,11 @@ public function testFindAllFolderHideRead()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(4))
$this->builder->expects($this->exactly(5))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['x IS NULL'],
['items.id < :offset'],
['items.unread = 1']
Expand Down Expand Up @@ -920,10 +929,11 @@ public function testFindAllFolderHideReadInvertOrder()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(4))
$this->builder->expects($this->exactly(5))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['x IS NULL'],
['items.id > :offset'],
['items.unread = 1']
Expand Down Expand Up @@ -1008,10 +1018,11 @@ public function testFindAllFolderSearchId()
->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id'])
->will($this->returnSelf());

$this->builder->expects($this->exactly(5))
$this->builder->expects($this->exactly(6))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['x = y'],
['items.search_index LIKE :term0'],
['items.search_index LIKE :term1'],
Expand Down Expand Up @@ -1061,4 +1072,4 @@ public function testFindAllFolderSearchId()
$this->assertEquals([Item::fromRow(['id' => 4])], $result);
}

}
}

0 comments on commit 69efb75

Please sign in to comment.