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

Updater/newlogic #2999

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .github/workflows/api-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ jobs:
app: 'news'
check-code: false
force: ${{ matrix.experimental }}

- name: DEBUG print jq version and build configuration
run: jq -V && jq --build-configuration

- name: Run API tests
working-directory: ../server
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
# Unreleased
## [25.x.x]
### Changed
- API add new field to Feed that indicates when the next update will be done "nextUpdateTime" (#2993)
- Change logic to update feed only if the nextUpdateTime has been reached ()

### Fixed

Expand Down
9 changes: 2 additions & 7 deletions docs/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
By default, the value is set to 3600 seconds (1 hour) You can configure this interval as an administrator.
The new value is only applied after the next run of the updater.

#### What is a good update interval?
Since News 25.2.0 news no longer will update all feeds instaed it will make a induvidual decision based on when an update for the feed will make sense. Thefore this intervall is now only to be understood as the check if an update should be done.

Check warning on line 66 in docs/admin.md

View workflow job for this annotation

GitHub Actions / typos

"instaed" should be "instead".

Check warning on line 66 in docs/admin.md

View workflow job for this annotation

GitHub Actions / typos

"Thefore" should be "Therefore".

Check warning on line 66 in docs/admin.md

View workflow job for this annotation

GitHub Actions / typos

"intervall" should be "interval".

Check failure on line 66 in docs/admin.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'instaed'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'instaed'?", "location": {"path": "docs/admin.md", "range": {"start": {"line": 66, "column": 56}}}, "severity": "ERROR"}

Check failure on line 66 in docs/admin.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'induvidual'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'induvidual'?", "location": {"path": "docs/admin.md", "range": {"start": {"line": 66, "column": 79}}}, "severity": "ERROR"}

Check failure on line 66 in docs/admin.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'Thefore'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Thefore'?", "location": {"path": "docs/admin.md", "range": {"start": {"line": 66, "column": 153}}}, "severity": "ERROR"}

Check failure on line 66 in docs/admin.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'intervall'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'intervall'?", "location": {"path": "docs/admin.md", "range": {"start": {"line": 66, "column": 166}}}, "severity": "ERROR"}

That depends on your individual needs.
Please keep in mind that the lower you set your update interval, the more traffic is generated.

#### Can I set individual update intervals per feed/user?

No, that is not possible.
Some feeds might not provide enough information to calculate the next update time those will be updated based on the update interval.
2 changes: 2 additions & 0 deletions docs/api/api-v1-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ The following attributes are **not sanitized** meaning: including them in your w
"added": 1367063790,
"folderId": 4,
"unreadCount": 9,
"nextUpdateTime": 2071387335,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
"link": "http://theoatmeal.com/",
"pinned": true // if a feed should be sorted before other feeds, added in 6.0.3,
Expand Down Expand Up @@ -341,6 +342,7 @@ Creates a new feed and returns the feed
"title": "The Oatmeal - Comics, Quizzes, & Stories",
"faviconLink": "http://theoatmeal.com/favicon.ico",
"added": 1367063790,
"nextUpdateTime": 2071387335,
"folderId": 4,
"unreadCount": 9,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
Expand Down
2 changes: 2 additions & 0 deletions docs/api/api-v1-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ The following attributes are **not sanitized** meaning: including them in your w
"title": "The Oatmeal - Comics, Quizzes, & Stories",
"faviconLink": "http://theoatmeal.com/favicon.ico",
"added": 1367063790,
"nextUpdateTime": 2071387335,
"folderId": 4,
"unreadCount": 9,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
Expand Down Expand Up @@ -341,6 +342,7 @@ Creates a new feed and returns the feed
"title": "The Oatmeal - Comics, Quizzes, & Stories",
"faviconLink": "http://theoatmeal.com/favicon.ico",
"added": 1367063790,
"nextUpdateTime": 2071387335,
"folderId": 4,
"unreadCount": 9,
"ordering": 0, // 0 means no special ordering, 1 means oldest first, 2 newest first, new in 5.1.0
Expand Down
14 changes: 14 additions & 0 deletions docs/user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# User

Welcome to the User documentaion of News.

Check warning on line 3 in docs/user.md

View workflow job for this annotation

GitHub Actions / typos

"documentaion" should be "documentation".

Check failure on line 3 in docs/user.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'documentaion'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'documentaion'?", "location": {"path": "docs/user.md", "range": {"start": {"line": 3, "column": 21}}}, "severity": "ERROR"}

# TODO
This documentation is work in progress

# User interface

explain the different options in the UI especially options for feeds and settings

# Using News with Clients

explain sync and link to clients page
29 changes: 26 additions & 3 deletions lib/Db/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Feed extends Entity implements IAPI, \JsonSerializable
protected $basicAuthUser = '';
/** @var string|null */
protected $basicAuthPassword = '';
/** @var int|null */
protected ?int $nextUpdateTime = null;
/** @var Item[] */
public $items = [];

Expand Down Expand Up @@ -110,6 +112,7 @@ public function __construct()
$this->addType('lastUpdateError', 'string');
$this->addType('basicAuthUser', 'string');
$this->addType('basicAuthPassword', 'string');
$this->addType('nextUpdateTime', 'int');
}

/**
Expand Down Expand Up @@ -296,6 +299,14 @@ public function getUserId(): string
return $this->userId;
}

/**
* @return int|null
*/
public function getNextUpdateTime(): ?int
{
return $this->nextUpdateTime;
}

/**
* Turns entity attributes into an array
*/
Expand Down Expand Up @@ -323,7 +334,8 @@ public function jsonSerialize(): array
'updateErrorCount',
'lastUpdateError',
'basicAuthUser',
'basicAuthPassword'
'basicAuthPassword',
'nextUpdateTime'
]);

if (is_null($this->link)) {
Expand Down Expand Up @@ -648,6 +660,15 @@ public function setUserId(string $userId): Feed
return $this;
}

/**
* @param int $nextUpdateTime
*/
public function setNextUpdateTime(int $nextUpdateTime): void
{
$this->nextUpdateTime = $nextUpdateTime;
$this->markFieldUpdated('nextUpdateTime');
}

public function toAPI(): array
{
return $this->serializeFields(
Expand All @@ -664,7 +685,8 @@ public function toAPI(): array
'pinned',
'updateErrorCount',
'lastUpdateError',
'items'
'items',
'nextUpdateTime'
]
);
}
Expand All @@ -679,7 +701,8 @@ public function toAPI2(bool $reduced = false): array
'ordering' => $this->getOrdering(),
'fullTextEnabled' => $this->getFullTextEnabled(),
'updateMode' => $this->getUpdateMode(),
'isPinned' => $this->getPinned()
'isPinned' => $this->getPinned(),
'nextUpdateTime' => $this->getNextUpdateTime(),
];

if (!is_null($this->getLastUpdateError()) || trim($this->getLastUpdateError()) !== '') {
Expand Down
2 changes: 2 additions & 0 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public function fetch(
$location
);

$feed->setNextUpdateTime($resource->getNextUpdate()?->getTimestamp());

if (!is_null($resource->getResponse()->getLastModified())) {
$feed->setHttpLastModified($resource->getResponse()->getLastModified()->format(DateTime::RSS));
} elseif (!is_null($lastModified)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version250000Date20240817095614.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use OCP\Migration\SimpleMigrationStep;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
* allows the title of a news feed to be null
*/
class Version250000Date20240817095614 extends SimpleMigrationStep {

Expand Down
56 changes: 56 additions & 0 deletions lib/Migration/Version250200Date20241219085150.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\News\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Adds the next_update_time column to the feeds table
*/
class Version250200Date20241219085150 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

$table = $schema->getTable('news_feeds');
if (!$table->hasColumn('next_update_time')) {
$table->addColumn('next_update_time', 'bigint', [
'notnull' => false
]);
}

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
13 changes: 13 additions & 0 deletions lib/Service/FeedServiceV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ public function fetch(Entity $feed): Entity
return $feed;
}

$nextUpdateTime = $feed->getNextUpdateTime();
$currentTime = time();
$tolerance = 10 * 60; // 10 minutes tolerance

if ($nextUpdateTime !== null && ($currentTime + $tolerance) < $nextUpdateTime) {
$this->logger->info('Feed update skipped. Next update time not reached.', [
'feedUrl' => $feed->getUrl(),
'nextUpdateTime' => $nextUpdateTime,
'currentTime' => $currentTime,
]);
return $feed;
}

// for backwards compatibility it can be that the location is not set
// yet, if so use the url
$location = $feed->getLocation() ?? $feed->getUrl();
Expand Down
7 changes: 5 additions & 2 deletions tests/Unit/Db/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function testToAPI()
'updateErrorCount' => 2,
'lastUpdateError' => 'hi',
'items' => [],
'nextUpdateTime' => ''
],
$feed->toAPI()
);
Expand All @@ -86,7 +87,8 @@ public function testToAPI2()
'error' => [
'code' => 1,
'message' => 'hi'
]
],
'nextUpdateTime' => '',
],
$feed->toAPI2()
);
Expand Down Expand Up @@ -121,7 +123,8 @@ public function testSerialize()
'updateErrorCount' => 2,
'lastUpdateError' => 'hi',
'basicAuthUser' => 'user',
'basicAuthPassword' => 'password'
'basicAuthPassword' => 'password',
'nextUpdateTime' => '',
],
$feed->jsonSerialize()
);
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Fetcher/FeedFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ private function createFeed($lang = 'de-DE', $url = null)
$feed->setLocation($this->location);
$feed->setUrl($url);
$feed->setAdded($this->time);
$feed->setNextUpdateTime(0);

$feed->setFaviconLink('http://anon.google.com');
$this->favicon->expects($this->exactly(1))
Expand Down
6 changes: 6 additions & 0 deletions tests/api/feeds.bats
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ teardown() {
done
}

@test "[$TESTSUITE] Create Feed and check for nextUpdateTime {
# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$NC_FEED | jq '.feeds | .[0].nextUpdateTime')
assert_output '2071387335'
}
22 changes: 11 additions & 11 deletions tests/test_helper/feeds/Nextcloud.rss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<atom:link href="http://localhost:8090/Nextcloud.rss" rel="self" type="application/rss+xml" />
<link>https://nextcloud.com/</link>
<description></description>
<lastBuildDate>Tue, 16 Aug 2099 10:17:13 +0000</lastBuildDate>
<lastBuildDate>Tue, 16 Aug 2035 10:17:13 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>
hourly </sy:updatePeriod>
Expand All @@ -32,7 +32,7 @@
<link>https://nextcloud.com/blog/how-to-get-started-with-nextcloud-repeat/</link>

<dc:creator><![CDATA[Fabrice Mous]]></dc:creator>
<pubDate>Tue, 16 Aug 2099 09:44:01 +0000</pubDate>
<pubDate>Tue, 16 Aug 2035 09:44:01 +0000</pubDate>
<category><![CDATA[business]]></category>
<category><![CDATA[News]]></category>
<category><![CDATA[Webinar]]></category>
Expand Down Expand Up @@ -116,7 +116,7 @@
<link>https://nextcloud.com/blog/openproject-and-nextcloud-integrate-project-management-and-file-management/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Mon, 15 Aug 2099 12:44:53 +0000</pubDate>
<pubDate>Mon, 15 Aug 2035 12:44:53 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[business]]></category>
<category><![CDATA[partner]]></category>
Expand Down Expand Up @@ -160,7 +160,7 @@
<link>https://nextcloud.com/blog/5-more-things-to-keep-your-data-safe/</link>

<dc:creator><![CDATA[Mikaela Schneider]]></dc:creator>
<pubDate>Wed, 10 Aug 2099 09:06:12 +0000</pubDate>
<pubDate>Wed, 10 Aug 2035 09:06:12 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[Community]]></category>
<category><![CDATA[general]]></category>
Expand Down Expand Up @@ -360,7 +360,7 @@
<link>https://nextcloud.com/blog/digital-sovereignty-security-collabora-online-nextcloud/</link>

<dc:creator><![CDATA[Fabrice Mous]]></dc:creator>
<pubDate>Thu, 04 Aug 2099 13:07:21 +0000</pubDate>
<pubDate>Thu, 04 Aug 2035 13:07:21 +0000</pubDate>
<category><![CDATA[business]]></category>
<category><![CDATA[News]]></category>
<category><![CDATA[Webinar]]></category>
Expand Down Expand Up @@ -444,7 +444,7 @@
<link>https://nextcloud.com/blog/nextcloud-keeps-growth-up-with-75-more-revenue-and-10x-userbase/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Thu, 04 Aug 2099 09:40:29 +0000</pubDate>
<pubDate>Thu, 04 Aug 2035 09:40:29 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[business]]></category>
<category><![CDATA[general]]></category>
Expand Down Expand Up @@ -506,7 +506,7 @@
<link>https://nextcloud.com/blog/baden-wurttemberg-procurement-chamber-decides-us-cloud-services-are-not-gdpr-compliant/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Mon, 01 Aug 2099 09:00:00 +0000</pubDate>
<pubDate>Mon, 01 Aug 2035 09:00:00 +0000</pubDate>
<category><![CDATA[business]]></category>
<category><![CDATA[general]]></category>
<category><![CDATA[News]]></category>
Expand Down Expand Up @@ -553,7 +553,7 @@
<link>https://nextcloud.com/blog/interview-shadow-and-a-world-where-5-companies-own-all-data/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Mon, 01 Aug 2099 07:43:56 +0000</pubDate>
<pubDate>Mon, 01 Aug 2035 07:43:56 +0000</pubDate>
<category><![CDATA[general]]></category>
<category><![CDATA[News]]></category>
<category><![CDATA[partner]]></category>
Expand All @@ -579,7 +579,7 @@
<link>https://nextcloud.com/blog/all-app-developers-put-your-hands-up-best-nextcloud-app-contest-2/</link>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Thu, 28 Jul 2099 09:00:00 +0000</pubDate>
<pubDate>Thu, 28 Jul 2035 09:00:00 +0000</pubDate>
<category><![CDATA[Apps]]></category>
<category><![CDATA[Community]]></category>
<category><![CDATA[conference]]></category>
Expand Down Expand Up @@ -715,7 +715,7 @@
<link>https://nextcloud.com/blog/5-unique-security-features-by-nextcloud/</link>

<dc:creator><![CDATA[Mikaela Schneider]]></dc:creator>
<pubDate>Wed, 27 Jul 2099 14:36:15 +0000</pubDate>
<pubDate>Wed, 27 Jul 2035 14:36:15 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[general]]></category>
<category><![CDATA[Privacy Wednesday]]></category>
Expand Down Expand Up @@ -879,7 +879,7 @@
<comments>https://nextcloud.com/blog/nextcloud-in-the-wall-street-journal-microsoft-and-cookies/#comments</comments>

<dc:creator><![CDATA[Jos Poortvliet]]></dc:creator>
<pubDate>Wed, 27 Jul 2099 09:12:45 +0000</pubDate>
<pubDate>Wed, 27 Jul 2035 09:12:45 +0000</pubDate>
<category><![CDATA[blog]]></category>
<category><![CDATA[business]]></category>
<category><![CDATA[general]]></category>
Expand Down
Loading
Loading