Skip to content

Commit

Permalink
update feed only if nextUpdateTime has been reached
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Brahmer <[email protected]>
  • Loading branch information
Grotax committed Dec 22, 2024
1 parent ed9fef2 commit 7dd001c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
## [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
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

0 comments on commit 7dd001c

Please sign in to comment.