-
Notifications
You must be signed in to change notification settings - Fork 189
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: Fix offset quotes #1201
DB: Fix offset quotes #1201
Conversation
21410e6
to
38f1faa
Compare
Codecov Report
@@ Coverage Diff @@
## master #1201 +/- ##
============================================
+ Coverage 87.07% 87.15% +0.07%
- Complexity 691 693 +2
============================================
Files 60 60
Lines 2492 2484 -8
============================================
- Hits 2170 2165 -5
+ Misses 322 319 -3
Continue to review full report at Codecov.
|
Looks good 👍 |
It fetches the exact same articles again, resulting in not showing any new ones // inital: /apps/news/items?limit=40&oldestFirst=false&search=&showAll=true&type=6
{"newestItemId": 129155, "feeds": [ /* feed data */ ], "starred": 543, "items": [ /* 40 items */ ]} // after scrolling: /apps/news/items?limit=40&offset=129115&oldestFirst=false&showAll=true&type=6
{"items": [ /* 39 items */ ]} I had to make a few changes to make it work: diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php
index bfa1d111c..24c70ea89 100644
--- a/lib/Db/ItemMapperV2.php
+++ b/lib/Db/ItemMapperV2.php
@@ -412,10 +412,10 @@ class ItemMapperV2 extends NewsMapperV2
private function offsetWhere(bool $oldestFirst): string
{
if ($oldestFirst === true) {
- return 'items.id < :offset';
+ return 'items.id > :offset';
}
- return 'items.id > :offset';
+ return 'items.id < :offset';
}
/**
@@ -445,14 +445,17 @@ class ItemMapperV2 extends NewsMapperV2
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->andWhere('feeds.user_id = :userId')
->andWhere('items.feed_id = :feedId')
- ->andWhere($this->offsetWhere($oldestFirst))
->setParameter('userId', $userId)
->setParameter('feedId', $feedId)
- ->setParameter('offset', $offset)
->setMaxResults($limit)
->orderBy('items.last_modified', ($oldestFirst ? 'ASC' : 'DESC'))
->addOrderBy('items.id', ($oldestFirst ? 'ASC' : 'DESC'));
+ if ($offset !== 0) {
+ $builder->andWhere($this->offsetWhere($oldestFirst))
+ ->setParameter('offset', $offset);
+ }
+
if ($search !== []) {
foreach ($search as $key => $term) {
$term = $this->db->escapeLikeParameter($term);
@@ -501,13 +504,16 @@ class ItemMapperV2 extends NewsMapperV2
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->andWhere('feeds.user_id = :userId')
->andWhere($folderWhere)
- ->andWhere($this->offsetWhere($oldestFirst))
->setParameter('userId', $userId)
- ->setParameter('offset', $offset)
->setMaxResults($limit)
->orderBy('items.last_modified', ($oldestFirst ? 'ASC' : 'DESC'))
->addOrderBy('items.id', ($oldestFirst ? 'ASC' : 'DESC'));
+ if ($offset !== 0) {
+ $builder->andWhere($this->offsetWhere($oldestFirst))
+ ->setParameter('offset', $offset);
+ }
+
if ($search !== []) {
foreach ($search as $key => $term) {
$term = $this->db->escapeLikeParameter($term);
@@ -548,13 +554,16 @@ class ItemMapperV2 extends NewsMapperV2
->from($this->tableName, 'items')
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->andWhere('feeds.user_id = :userId')
- ->andWhere($this->offsetWhere($oldestFirst))
->setParameter('userId', $userId)
- ->setParameter('offset', $offset)
->setMaxResults($limit)
->orderBy('items.last_modified', ($oldestFirst ? 'ASC' : 'DESC'))
->addOrderBy('items.id', ($oldestFirst ? 'ASC' : 'DESC'));
+ if ($offset !== 0) {
+ $builder->andWhere($this->offsetWhere($oldestFirst))
+ ->setParameter('offset', $offset);
+ }
+
if ($search !== []) {
foreach ($search as $key => $term) {
$term = $this->db->escapeLikeParameter($term); I have adopted most of them from the old ItemMapper, after seaching for the differences..The operator has to be other way around Lines 202 to 209 in ceba810
The offset is apparently 0 for the initial request, so no offset filter should be appliedLines 333 to 337 in ceba810
|
Issue GH-1200 Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
38f1faa
to
a3b1ed3
Compare
Applied the patch, thanks @anoymouserver |
Really github? Request review means "dismiss existing reviews"? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work guys :)
Fixes GH-1200