aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-08-13 15:11:22 +0200
committerGravatar GitHub <noreply@github.com> 2023-08-13 15:11:22 +0200
commitd165ed1fb6096d5bd0558d3ed637e53bc728baa7 (patch)
tree4b563dcd60d467d684e06524f3772de8160d54ff /app/Models/EntryDAO.php
parent54592fa1fdb80b4865c76b530135aaa0eac438c7 (diff)
Fix hash of articles with loadCompleteContent (#5576)
* Fix hash of articles with loadCompleteContent The detection of modified articles was wrong for feeds using loadCompleteContent. Indeed, the hash is supposed to computed on the content provided by the server of the RSS feed, excluding further modifications. Furthermore, read hash from database instead of recomputing it all the time. Slightly related to https://github.com/FreshRSS/FreshRSS/pull/5574 * Explicit SQL alias * PHPDocs
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php18
1 files changed, 11 insertions, 7 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index e8a531ec0..8306320a0 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -729,8 +729,9 @@ SQL;
public function searchByGuid(int $id_feed, string $guid): ?FreshRSS_Entry {
$content = static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content';
+ $hash = static::sqlHexEncode('hash');
$sql = <<<SQL
-SELECT id, guid, title, author, link, date, is_read, is_favorite, id_feed, tags, attributes, {$content}
+SELECT id, guid, title, author, link, date, is_read, is_favorite, {$hash} AS hash, id_feed, tags, attributes, {$content}
FROM `_entry` WHERE id_feed=:id_feed AND guid=:guid
SQL;
$res = $this->fetchAssoc($sql, [':id_feed' => $id_feed, ':guid' => $guid]);
@@ -741,8 +742,9 @@ SQL;
public function searchById(string $id): ?FreshRSS_Entry {
$content = static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content';
+ $hash = static::sqlHexEncode('hash');
$sql = <<<SQL
-SELECT id, guid, title, author, link, date, is_read, is_favorite, id_feed, tags, attributes, {$content}
+SELECT id, guid, title, author, link, date, is_read, is_favorite, {$hash} AS hash, id_feed, tags, attributes, {$content}
FROM `_entry` WHERE id=:id
SQL;
$res = $this->fetchAssoc($sql, [':id' => $id]);
@@ -1136,9 +1138,10 @@ SQL;
if ($order !== 'DESC' && $order !== 'ASC') {
$order = 'DESC';
}
- $content = static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content';
+ $content = static::isCompressed() ? 'UNCOMPRESS(e0.content_bin) AS content' : 'e0.content';
+ $hash = static::sqlHexEncode('e0.hash');
$sql = <<<SQL
-SELECT e0.id, e0.guid, e0.title, e0.author, {$content}, e0.link, e0.date, e0.is_read, e0.is_favorite, e0.id_feed, e0.tags, e0.attributes
+SELECT e0.id, e0.guid, e0.title, e0.author, {$content}, e0.link, e0.date, {$hash} AS hash, e0.is_read, e0.is_favorite, e0.id_feed, e0.tags, e0.attributes
FROM `_entry` e0
INNER JOIN ({$sql}) e2 ON e2.id=e0.id
ORDER BY e0.id {$order}
@@ -1169,7 +1172,7 @@ SQL;
if ($stm) {
while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
/** @var array{'id':string,'id_feed':int,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int,
- * 'is_read':int,'is_favorite':int,'tags':string,'attributes'?:string} $row */
+ * 'hash':string,'is_read':int,'is_favorite':int,'tags':string,'attributes'?:string} $row */
yield FreshRSS_Entry::fromArray($row);
}
}
@@ -1198,9 +1201,10 @@ SQL;
$order = 'DESC';
}
$content = static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content';
+ $hash = static::sqlHexEncode('hash');
$repeats = str_repeat('?,', count($ids) - 1) . '?';
$sql = <<<SQL
-SELECT id, guid, title, author, link, date, is_read, is_favorite, id_feed, tags, attributes, {$content}
+SELECT id, guid, title, author, link, date, {$hash} AS hash, is_read, is_favorite, id_feed, tags, attributes, {$content}
FROM `_entry`
WHERE id IN ({$repeats})
ORDER BY id {$order}
@@ -1211,7 +1215,7 @@ SQL;
}
while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
/** @var array{'id':string,'id_feed':int,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int,
- * 'is_read':int,'is_favorite':int,'tags':string,'attributes'?:string} $row */
+ * 'hash':string,'is_read':int,'is_favorite':int,'tags':string,'attributes'?:string} $row */
yield FreshRSS_Entry::fromArray($row);
}
}