-
Notifications
You must be signed in to change notification settings - Fork 177
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
Mappers: Implement item purging #1065
Mappers: Implement item purging #1065
Conversation
c3f5c4f
to
387aaf1
Compare
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.
Furthermore we need to respect the oc_news_feeds.articles_per_update
count to avoid purging more items which would reappear with the next fetch and then be unread and, since they have a higher ID, be at the top of the list.
This would additionally output the article count:
SELECT items.feed_id, COUNT(items.id) itemCount, feeds.articles_per_update
FROM `oc_news_items` items
INNER JOIN `oc_news_feeds` feeds ON feeds.id = items.feed_id
GROUP BY items.feed_id;
otherwise it could be also calculated in the query (not useful, because it's needed again while deleting)
SELECT items.feed_id, (COUNT(items.id) - feeds.articles_per_update) itemCount
/* same as above .. */
A possible minimal solution for the article count to keep it simple: // first query from previous comment ..
$feedQb->addSelect('items.feed_id', $feedQb->func()->count('items.id', 'itemCount'), 'feeds.articles_per_update')
->from($this->tableName, 'items')
->innerJoin('items', FeedMapperV2::TABLE_NAME, 'feeds', 'items.feed_id = feeds.id')
->groupBy('items.feed_id');
// .. and then use this later on instead of just $threshold
$maxItems = max($threshold, $feed['articles_per_update']) |
387aaf1
to
f1b9c8b
Compare
Looks good so far, but I would test it before approving it. |
I was running the cleanup command locally and it works. CI will be fixed by #1072 |
If you can make an issue for it I'd be fine with making this optional in the next release. |
I feel a bit uncomfortable with a release of this, it would be an unexpected change when we roll this out and suddenly also unread items get deleted. What I could image is that we force the config value to 0/-1 on upgrade to disable the autopurge. |
bf4fb58
to
7c622a8
Compare
I've just tested the latest commit with NC 20.0.6 (PHP 7.3.25, MariaDB 10.1.47): # should do something since the [<purge_count>] is optional, but doesn't
$ occ news:updater:after-update
# does something but crashes :(
$ occ news:updater:after-update 100
What type (and version) of database do you use? |
It does something for me, try running it with
I tested it successfully with a local SQLite DB. Maybe you can find some ways to get around this issue? |
With It seems like MySQL and MariaDB doesn't support LIMIT in subqueries. |
dceeadd
to
0172b9c
Compare
Okay, moved the query. It's much messier now, but at least it will work on MySQL |
After changing this locally I've got
.. apparently you have to use a named (or postional) parameter for the array otherwise it assumes that the array items are column names. $deleteQb->delete($this->tableName)
->where('id IN (?)');
return $this->db->executeUpdate($deleteQb->getSQL(), [$total_items], [IQueryBuilder::PARAM_INT_ARRAY]); ⬆️ seems to work: |
I've noticed that not the oldest ones are removed but the most recent unread and unstared ones. -> seems to be solved by adding |
All of the mentioned (and tested) changes together: diff --git a/lib/Db/ItemMapperV2.php b/lib/Db/ItemMapperV2.php
index d888e9403..28cf748c8 100644
--- a/lib/Db/ItemMapperV2.php
+++ b/lib/Db/ItemMapperV2.php
@@ -165,7 +165,8 @@ class ItemMapperV2 extends NewsMapperV2
$rangeQuery->select('id')
->from($this->tableName)
->where('feed_id = :feedId')
- ->andWhere('starred = 0');
+ ->andWhere('starred = 0')
+ ->orderBy('id', 'DESC');
if ($removeUnread === false) {
$rangeQuery->andWhere('unread = 0');
@@ -187,9 +188,9 @@ class ItemMapperV2 extends NewsMapperV2
$deleteQb = $this->db->getQueryBuilder();
$deleteQb->delete($this->tableName)
- ->where($deleteQb->expr()->in('id', $total_items));
+ ->where('id IN (?)');
- return $this->db->executeStatement($deleteQb->getSQL());
+ return $this->db->executeUpdate($deleteQb->getSQL(), [$total_items], [IQueryBuilder::PARAM_INT_ARRAY]);
}
/**
|
0172b9c
to
81488d9
Compare
Codecov Report
@@ Coverage Diff @@
## master #1065 +/- ##
============================================
- Coverage 72.07% 68.84% -3.23%
- Complexity 681 734 +53
============================================
Files 58 73 +15
Lines 2417 2690 +273
============================================
+ Hits 1742 1852 +110
- Misses 675 838 +163
Continue to review full report at Codecov.
|
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
81488d9
to
da29b6d
Compare
Implement missing Mapper feature