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

Implement purgeUnread setting #1931

Merged
merged 2 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [Koen Martens](mailto:[email protected])
* [Lukas Reschke](mailto:[email protected])
* [Tucker McKnight](mailto:[email protected])
* [Valdnet](mailto:[email protected])
* [Bart Visscher](mailto:[email protected])
* [Christian Elmer](mailto:[email protected])
* [Nicolas Wendling](mailto:[email protected])
Expand Down Expand Up @@ -68,7 +69,6 @@
* [Nikita Chernyi](mailto:[email protected])
* [Peter Hedlund](mailto:[email protected])
* [Simon Spannagel](mailto:[email protected])
* [Valdnet](mailto:[email protected])
* [bbBowser](mailto:[email protected])
* [benediktb](mailto:[email protected])
* [chylex](mailto:[email protected])
Expand All @@ -84,6 +84,7 @@
* [Alexander Grüßung](mailto:[email protected])
* [Allan Nordhøy](mailto:[email protected])
* [Alwaysin](mailto:[email protected])
* [Anderson Silva](mailto:[email protected])
* [Andrea Boero](mailto:[email protected])
* [Andreas Demmelbauer](mailto:[email protected])
* [Artem Lavrukhin](mailto:[email protected])
Expand All @@ -94,6 +95,7 @@
* [Bernhard Posselt](mailto:[email protected])
* [Björn Bidar](mailto:[email protected])
* [Candid Dauth](mailto:[email protected])
* [Carl Schwan](mailto:[email protected])
* [Carlos Silva](mailto:[email protected])
* [Cesar Enrique Garcia Dabo](mailto:[email protected])
* [Chris Aumann](mailto:[email protected])
Expand Down Expand Up @@ -131,6 +133,7 @@
* [Martin Ferretti](mailto:[email protected])
* [Matthias](mailto:[email protected])
* [Matthias Blümel](mailto:[email protected])
* [Michael Chang](mailto:[email protected])
* [Michael Grosser](mailto:[email protected])
* [Michael Hamann](mailto:[email protected])
* [Michael Holley](mailto:[email protected])
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
# Unreleased
## [18.x.x]
### Changed

- New administrator setting for deleting unread items automatically (#1931)
### Fixed

# Releases
Expand Down
1 change: 1 addition & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Application extends App implements IBootstrap
public const DEFAULT_SETTINGS = [
'autoPurgeMinimumInterval' => 60,
'autoPurgeCount' => 200,
'purgeUnread' => false,
'maxRedirects' => 10,
'feedFetcherTimeout' => 60,
'useCronUpdates' => true,
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/ItemMapperV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ public function findAllForFeed(int $feedId): array
* Delete items from feed that are over the max item threshold
*
* @param int $threshold Deletion threshold
* @param bool $removeUnread If unread articles should be removed
* @param bool $purgeUnread If unread articles should be removed
*
* @return int|null Removed items
*
* @throws \Doctrine\DBAL\Exception
*/
public function deleteOverThreshold(int $threshold, bool $removeUnread = false): ?int
public function deleteOverThreshold(int $threshold, bool $purgeUnread): ?int
{
$feedQb = $this->db->getQueryBuilder();
$feedQb->select('feed_id', $feedQb->func()->count('*', 'itemCount'))
Expand All @@ -214,7 +214,7 @@ public function deleteOverThreshold(int $threshold, bool $removeUnread = false):
->andWhere('starred = false')
->addOrderBy('id', 'DESC');

if ($removeUnread === false) {
if ($purgeUnread === false) {
$rangeQuery->andWhere('unread = false');
}

Expand Down
14 changes: 10 additions & 4 deletions lib/Service/ItemServiceV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,30 @@ public function read(string $userId, int $id, bool $read): Entity
}

/**
* @param int|null $threshold
* @param bool $removeUnread
* @param int|null $threshold
* @param bool|null $purgeUnread
*
* @return int|null Amount of deleted items or null if not applicable
*/
public function purgeOverThreshold(int $threshold = null, bool $removeUnread = false): ?int
public function purgeOverThreshold(int $threshold = null, bool $purgeUnread = null): ?int
{
$threshold = (int) ($threshold ?? $this->config->getAppValue(
Application::NAME,
'autoPurgeCount',
Application::DEFAULT_SETTINGS['autoPurgeCount']
));

$purgeUnread = (bool) ($purgeUnread ?? $this->config->getAppValue(
Application::NAME,
'purgeUnread',
Application::DEFAULT_SETTINGS['purgeUnread']
));

if ($threshold <= 0) {
return null;
}

return $this->mapper->deleteOverThreshold($threshold, $removeUnread);
return $this->mapper->deleteOverThreshold($threshold, $purgeUnread);
}
/**
* Mark an item as starred
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/UpdaterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public function update(): void

public function afterUpdate(): void
{
$this->itemService->purgeOverThreshold(null);
$this->itemService->purgeOverThreshold();
}
}
10 changes: 9 additions & 1 deletion src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ SPDX-Licence-Identifier: AGPL-3.0-or-later
@update:value="update('autoPurgeCount', autoPurgeCount)" />
<p><em>{{ t('news', 'Defines the maximum amount of articles that can be read per feed which will not be deleted by the cleanup job; if old articles reappear after being read, increase this value; negative values such as -1 will turn this feature off.') }}</em></p>

<NcCheckboxRadioSwitch type="switch"
:checked.sync="purgeUnread"
@update:checked="update('purgeUnread', purgeUnread)">
{{ t('news', 'Delete unread items automatically') }}
</NcCheckboxRadioSwitch>
<p><em>{{ t('news', 'Enable this if you also want to delete unread items. Consider increasing the value above.') }}</em></p>

<NcTextField :value.sync="maxRedirects"
:label="t('news', 'Maximum redirects')"
:label-visible="true"
Expand Down Expand Up @@ -90,6 +97,7 @@ export default {
useCronUpdates: loadState('news', 'useCronUpdates') === '1',
autoPurgeMinimumInterval: loadState('news', 'autoPurgeMinimumInterval'),
autoPurgeCount: loadState('news', 'autoPurgeCount'),
purgeUnread: loadState('news', 'purgeUnread') === '1',
maxRedirects: loadState('news', 'maxRedirects'),
feedFetcherTimeout: loadState('news', 'feedFetcherTimeout'),
exploreUrl: loadState('news', 'exploreUrl'),
Expand All @@ -103,7 +111,7 @@ export default {
appId: 'news',
key,
})
if (key === 'useCronUpdates') {
if (key === 'useCronUpdates' || key === 'purgeUnread') {
value = value ? '1' : '0'
}
try {
Expand Down
15 changes: 8 additions & 7 deletions tests/Unit/Service/ItemServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,23 +605,24 @@ public function testPurgeOverThresholdWithNegative()

public function testPurgeOverThresholdNull()
{
$this->config->expects($this->once())
$this->config->expects($this->exactly(2))
->method('getAppValue')
->with('news', 'autoPurgeCount', 200)
->will($this->returnValue(200));

->withConsecutive(['news', 'autoPurgeCount', 200], ['news', 'purgeUnread', false])
->willReturnOnConsecutiveCalls(200, false);
$this->mapper->expects($this->once())
->method('deleteOverThreshold')
->with(200);
->with(200, false);

$this->class->purgeOverThreshold();
}

public function testPurgeOverThresholdSet()
{
$this->config->expects($this->never())
$this->config->expects($this->once())
->method('getAppValue')
->with('news', 'autoPurgeCount', 200);
->with('news', 'purgeUnread', false)
->will($this->returnValue(false));

$this->mapper->expects($this->once())
->method('deleteOverThreshold')
Expand Down