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 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
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:gmc@sonologic.nl)
* [Lukas Reschke](mailto:lukas@owncloud.com)
* [Tucker McKnight](mailto:tucker.mcknight@gmail.com)
* [Valdnet](mailto:47037905+Valdnet@users.noreply.github.com)
* [Bart Visscher](mailto:bartv@thisnet.nl)
* [Christian Elmer](mailto:christian@keinkurt.de)
* [Nicolas Wendling](mailto:nicolas.wendling1011@gmail.com)
Expand Down Expand Up @@ -68,7 +69,6 @@
* [Nikita Chernyi](mailto:rakshazi@users.noreply.github.com)
* [Peter Hedlund](mailto:peter@peterandlinda.com)
* [Simon Spannagel](mailto:simonspa@kth.se)
* [Valdnet](mailto:47037905+Valdnet@users.noreply.github.com)
* [bbBowser](mailto:carspi@mail.de)
* [benediktb](mailto:benedikt@blablub.de)
* [chylex](mailto:contact@chylex.com)
Expand All @@ -84,6 +84,7 @@
* [Alexander Grüßung](mailto:alexander@gruessung-online.de)
* [Allan Nordhøy](mailto:epost@anotheragency.no)
* [Alwaysin](mailto:adrien@demma.fr)
* [Anderson Silva](mailto:UnderEu@users.noreply.github.com)
* [Andrea Boero](mailto:mail@tsumi.it)
* [Andreas Demmelbauer](mailto:git@notice.at)
* [Artem Lavrukhin](mailto:lavryha4590@gmail.com)
Expand All @@ -94,6 +95,7 @@
* [Bernhard Posselt](mailto:bernhard@desktop.localdomain)
* [Björn Bidar](mailto:bjorn.bidar@thaodan.de)
* [Candid Dauth](mailto:cdauth@cdauth.eu)
* [Carl Schwan](mailto:carl@carlschwan.eu)
* [Carlos Silva](mailto:r3pek@r3pek.org)
* [Cesar Enrique Garcia Dabo](mailto:enrique@engarda.org)
* [Chris Aumann](mailto:me@chr4.org)
Expand Down Expand Up @@ -131,6 +133,7 @@
* [Martin Ferretti](mailto:ferrettimartin@protonmail.com)
* [Matthias](mailto:matthias.baier@mabaart.de)
* [Matthias Blümel](mailto:user@inanna.local)
* [Michael Chang](mailto:github@micbase.com)
* [Michael Grosser](mailto:github@stp-ip.net)
* [Michael Hamann](mailto:michael@content-space.de)
* [Michael Holley](mailto:michaelwholley@gmail.com)
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.') }}</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