Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB: Use boolean parameter for unread/starred #1279

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1

### Fixed
- Allow negative limits (#1275)
- Use boolean to check bool fields (#1278)

## [15.4.0-beta3] - 2021-04-03
### Changed
Expand Down
34 changes: 21 additions & 13 deletions lib/Db/ItemMapperV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ public function findAllInFeedAfter(
->addOrderBy('items.id', 'DESC');

if ($hideRead === true) {
$builder->andWhere('items.unread = 1');
$builder->andWhere('items.unread = :unread')
->setParameter('unread', true);
}

return $this->findEntities($builder);
Expand Down Expand Up @@ -377,7 +378,8 @@ public function findAllInFolderAfter(
->addOrderBy('items.id', 'DESC');

if ($hideRead === true) {
$builder->andWhere('items.unread = 1');
$builder->andWhere('items.unread = :unread')
->setParameter('unread', true);
}

return $this->findEntities($builder);
Expand Down Expand Up @@ -407,10 +409,12 @@ public function findAllAfter(string $userId, int $feedType, int $updatedSince):

switch ($feedType) {
case ListType::STARRED:
$builder->andWhere('items.starred = 1');
$builder->andWhere('items.starred = :starred')
->setParameter('starred', true);
break;
case ListType::UNREAD:
$builder->andWhere('items.unread = 1');
$builder->andWhere('items.unread = :unread')
->setParameter('unread', true);
break;
case ListType::ALL_ITEMS:
break;
Expand Down Expand Up @@ -474,7 +478,7 @@ public function findAllFeed(
foreach ($search as $key => $term) {
$term = $this->db->escapeLikeParameter($term);
$builder->andWhere("items.search_index LIKE :term${key}")
->setParameter("term${key}", "%$term%");
->setParameter("term${key}", "%$term%");
}
}

Expand All @@ -484,11 +488,12 @@ public function findAllFeed(

if ($offset !== 0) {
$builder->andWhere($this->offsetWhere($oldestFirst))
->setParameter('offset', $offset);
->setParameter('offset', $offset);
}

if ($hideRead === true) {
$builder->andWhere('items.unread = 1');
$builder->andWhere('items.unread = :unread')
->setParameter('unread', true);
}

return $this->findEntities($builder);
Expand Down Expand Up @@ -536,7 +541,7 @@ public function findAllFolder(
foreach ($search as $key => $term) {
$term = $this->db->escapeLikeParameter($term);
$builder->andWhere("items.search_index LIKE :term${key}")
->setParameter("term${key}", "%$term%");
->setParameter("term${key}", "%$term%");
}
}

Expand All @@ -546,11 +551,12 @@ public function findAllFolder(

if ($offset !== 0) {
$builder->andWhere($this->offsetWhere($oldestFirst))
->setParameter('offset', $offset);
->setParameter('offset', $offset);
}

if ($hideRead === true) {
$builder->andWhere('items.unread = 1');
$builder->andWhere('items.unread = :unread')
->setParameter('unread', true);
}

return $this->findEntities($builder);
Expand Down Expand Up @@ -600,15 +606,17 @@ public function findAllItems(

if ($offset !== 0) {
$builder->andWhere($this->offsetWhere($oldestFirst))
->setParameter('offset', $offset);
->setParameter('offset', $offset);
}

switch ($type) {
case ListType::STARRED:
$builder->andWhere('items.starred = 1');
$builder->andWhere('items.starred = :starred')
->setParameter('starred', true);
break;
case ListType::UNREAD:
$builder->andWhere('items.unread = 1');
$builder->andWhere('items.unread = :unread')
->setParameter('unread', true);
break;
case ListType::ALL_ITEMS:
break;
Expand Down
28 changes: 24 additions & 4 deletions tests/Unit/Db/ItemMapperAfterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function testFindAllInFeedAfterHideRead()
['feeds.user_id = :userId'],
['feeds.id = :feedId'],
['feeds.deleted_at = 0'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

Expand All @@ -147,6 +147,11 @@ public function testFindAllInFeedAfterHideRead()
])
->will($this->returnSelf());

$this->builder->expects($this->exactly(1))
->method('setParameter')
->with('unread', true)
->will($this->returnSelf());

$this->builder->expects($this->once())
->method('orderBy')
->with('items.last_modified', 'DESC')
Expand Down Expand Up @@ -271,7 +276,7 @@ public function testFindAllInFolderAfterHideRead()
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['folders.id = :folderId'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

Expand All @@ -284,6 +289,11 @@ public function testFindAllInFolderAfterHideRead()
])
->will($this->returnSelf());

$this->builder->expects($this->exactly(1))
->method('setParameter')
->with('unread', true)
->will($this->returnSelf());

$this->builder->expects($this->once())
->method('orderBy')
->with('items.last_modified', 'DESC')
Expand Down Expand Up @@ -336,7 +346,7 @@ public function testFindAllAfterUnread()
['items.last_modified >= :updatedSince'],
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

Expand All @@ -348,6 +358,11 @@ public function testFindAllAfterUnread()
])
->will($this->returnSelf());

$this->builder->expects($this->exactly(1))
->method('setParameter')
->with('unread', true)
->will($this->returnSelf());

$this->builder->expects($this->once())
->method('orderBy')
->with('items.last_modified', 'DESC')
Expand Down Expand Up @@ -400,7 +415,7 @@ public function testFindAllAfterStarred()
['items.last_modified >= :updatedSince'],
['feeds.deleted_at = 0'],
['feeds.user_id = :userId'],
['items.starred = 1']
['items.starred = :starred']
)
->will($this->returnSelf());

Expand All @@ -412,6 +427,11 @@ public function testFindAllAfterStarred()
])
->will($this->returnSelf());

$this->builder->expects($this->exactly(1))
->method('setParameter')
->with('starred', true)
->will($this->returnSelf());

$this->builder->expects($this->once())
->method('orderBy')
->with('items.last_modified', 'DESC')
Expand Down
48 changes: 27 additions & 21 deletions tests/Unit/Db/ItemMapperPaginatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ public function testFindAllItemsUnread()
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['items.id < :offset'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['offset', 10])
->withConsecutive(['userId', 'jack'], ['offset', 10], ['unread', true])
->will($this->returnSelf());

$this->builder->expects($this->exactly(1))
Expand Down Expand Up @@ -286,13 +286,13 @@ public function testFindAllItemsUnreadNoLimit()
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['items.id < :offset'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['offset', 10])
->withConsecutive(['userId', 'jack'], ['offset', 10], ['unread', true])
->will($this->returnSelf());

$this->builder->expects($this->never())
Expand Down Expand Up @@ -355,13 +355,13 @@ public function testFindAllItemsStarred()
['feeds.user_id = :userId'],
['feeds.deleted_at = 0'],
['items.id < :offset'],
['items.starred = 1']
['items.starred = :starred']
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['offset', 10])
->withConsecutive(['userId', 'jack'], ['offset', 10], ['starred', true])
->will($this->returnSelf());


Expand Down Expand Up @@ -432,13 +432,19 @@ public function testFindAllItemsStarredSearch()
['items.search_index LIKE :term0'],
['items.search_index LIKE :term1'],
['items.id < :offset'],
['items.starred = 1']
['items.starred = :starred']
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(4))
$this->builder->expects($this->exactly(5))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['term0', '%key%'], ['term1', '%word%'], ['offset', 10])
->withConsecutive(
['userId', 'jack'],
['term0', '%key%'],
['term1', '%word%'],
['offset', 10],
['starred', true]
)
->will($this->returnSelf());


Expand Down Expand Up @@ -721,13 +727,13 @@ public function testFindAllFeedHideRead()
['feeds.user_id = :userId'],
['items.feed_id = :feedId'],
['items.id < :offset'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(3))
$this->builder->expects($this->exactly(4))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['feedId', 2], ['offset', 10])
->withConsecutive(['userId', 'jack'], ['feedId', 2], ['offset', 10], ['unread', true])
->will($this->returnSelf());


Expand Down Expand Up @@ -1059,13 +1065,13 @@ public function testFindAllFolderHideRead()
['feeds.deleted_at = 0'],
['x IS NULL'],
['items.id < :offset'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['offset', 10])
->withConsecutive(['userId', 'jack'], ['offset', 10], ['unread', true])
->will($this->returnSelf());


Expand Down Expand Up @@ -1145,13 +1151,13 @@ public function testFindAllFolderHideReadInvertOrder()
['feeds.deleted_at = 0'],
['x IS NULL'],
['items.id > :offset'],
['items.unread = 1']
['items.unread = :unread']
)
->will($this->returnSelf());

$this->builder->expects($this->exactly(2))
$this->builder->expects($this->exactly(3))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['offset', 10])
->withConsecutive(['userId', 'jack'], ['offset', 10], ['unread', true])
->will($this->returnSelf());


Expand Down