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

Improve markAsReadUponGone #5315

Merged
merged 7 commits into from Apr 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/Controllers/feedController.php
Expand Up @@ -531,7 +531,10 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force

$feedDAO->updateLastUpdate($feed->id(), false, $mtime);
$needFeedCacheRefresh |= ($feed->keepMaxUnread() != false);
$needFeedCacheRefresh |= ($feed->markAsReadUponGone() != false);
if (!$simplePiePush) {
// Do not call for WebSub events, as we do not know the list of articles still on the upstream feed.
$needFeedCacheRefresh |= ($feed->markAsReadUponGone() != false);
}
if ($needFeedCacheRefresh) {
$feedDAO->updateCachedValues($feed->id());
}
Expand Down
18 changes: 10 additions & 8 deletions app/Models/Feed.php
Expand Up @@ -278,7 +278,7 @@ public function _url(string $value, bool $validate = true): void {
if ($validate) {
$url = checkUrl($url);
}
if ($url == '') {
if ($url == false) {
throw new FreshRSS_BadUrl_Exception($value);
}
$this->url = $url;
Expand Down Expand Up @@ -306,7 +306,7 @@ public function _website(string $value, bool $validate = true): void {
if ($validate) {
$value = checkUrl($value);
}
if ($value == '') {
if ($value == false) {
$value = '';
}
$this->website = $value;
Expand Down Expand Up @@ -448,7 +448,8 @@ public function loadGuids(SimplePie $simplePie): array {
$hasUniqueGuids = true;
$testGuids = [];
$guids = [];
$hasBadGuids = $this->attributes('hasBadGuids');
$links = [];
$hadBadGuids = $this->attributes('hasBadGuids');

$items = $simplePie->get_items();
if (empty($items)) {
Expand All @@ -463,19 +464,20 @@ public function loadGuids(SimplePie $simplePie): array {
$hasUniqueGuids &= empty($testGuids['_' . $guid]);
$testGuids['_' . $guid] = true;
$guids[] = $guid;
$links[] = $item->get_permalink();
}

if ($hasBadGuids != !$hasUniqueGuids) {
$hasBadGuids = !$hasUniqueGuids;
if ($hasBadGuids) {
if ($hadBadGuids != !$hasUniqueGuids) {
if ($hadBadGuids) {
Minz_Log::warning('Feed has invalid GUIDs: ' . $this->url);
} else {
Minz_Log::warning('Feed has valid GUIDs again: ' . $this->url);
}
$feedDAO = FreshRSS_Factory::createFeedDao();
$feedDAO->updateFeedAttribute($this, 'hasBadGuids', $hasBadGuids);
$feedDAO->updateFeedAttribute($this, 'hasBadGuids', !$hasUniqueGuids);
}
return $guids;

return $hasUniqueGuids ? $guids : $links;
}

/** @return iterable<FreshRSS_Entry> */
Expand Down
15 changes: 11 additions & 4 deletions app/Models/FeedDAO.php
Expand Up @@ -69,7 +69,7 @@ public function addFeed(array $valuesTmp) {
);

if ($stm && $stm->execute($values)) {
return $this->pdo->lastInsertId('`_feed_id_seq`');
return (int)($this->pdo->lastInsertId('`_feed_id_seq`'));
} else {
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
if ($this->autoUpdateDb($info)) {
Expand Down Expand Up @@ -355,7 +355,7 @@ public function listFeedsNewestItemUsec(?int $id_feed = null): array {
}

/**
* Use $defaultCacheDuration == -1 to return all feeds, without filtering them by TTL.
* @param int $defaultCacheDuration Use -1 to return all feeds, without filtering them by TTL.
* @return array<FreshRSS_Feed>
*/
public function listFeedsOrderUpdate(int $defaultCacheDuration = 3600, int $limit = 0): array {
Expand Down Expand Up @@ -496,13 +496,20 @@ public function markAsReadUponGone(int $id) {
//Double SELECT for MySQL workaround ERROR 1093 (HY000)
$sql = <<<'SQL'
UPDATE `_entry` SET is_read=1
WHERE id_feed=:id_feed1 AND is_read=0 AND `lastSeen` < (SELECT e3.maxlastseen FROM (
SELECT MAX(e2.`lastSeen`) AS maxlastseen FROM `_entry` e2 WHERE e2.id_feed = :id_feed2) e3)
WHERE id_feed=:id_feed1 AND is_read=0 AND (
`lastSeen` + 60 < (SELECT s1.maxlastseen FROM (
SELECT MAX(e2.`lastSeen`) AS maxlastseen FROM `_entry` e2 WHERE e2.id_feed = :id_feed2
) s1)
OR `lastSeen` + 60 < (SELECT s2.lastcorrectupdate FROM (
SELECT f2.`lastUpdate` AS lastcorrectupdate FROM `_feed` f2 WHERE f2.id = :id_feed3 AND f2.error = 0
) s2)
)
SQL;

if (($stm = $this->pdo->prepare($sql)) &&
$stm->bindParam(':id_feed1', $id, PDO::PARAM_INT) &&
$stm->bindParam(':id_feed2', $id, PDO::PARAM_INT) &&
$stm->bindParam(':id_feed3', $id, PDO::PARAM_INT) &&
$stm->execute()) {
return $stm->rowCount();
} else {
Expand Down