|
|
@@ -812,27 +812,31 @@ SQL;
|
|
|
|
|
|
public function searchByGuid(int $id_feed, string $guid): ?FreshRSS_Entry {
|
|
|
$content = static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content';
|
|
|
+ $contentLength = 'LENGTH(' . (static::isCompressed() ? 'content_bin' : 'content') . ') AS content_length';
|
|
|
$hash = static::sqlHexEncode('hash');
|
|
|
$sql = <<<SQL
|
|
|
-SELECT id, guid, title, author, {$content}, link, date, `lastSeen`, `lastUserModified`, {$hash} AS hash, is_read, is_favorite, id_feed, tags, attributes
|
|
|
+SELECT id, guid, title, author, {$content}, link, date, `lastSeen`, `lastUserModified`, {$hash} AS hash, is_read, is_favorite, id_feed, tags, attributes,
|
|
|
+ {$contentLength}
|
|
|
FROM `_entry` WHERE id_feed=:id_feed AND guid=:guid
|
|
|
SQL;
|
|
|
$res = $this->fetchAssoc($sql, [':id_feed' => $id_feed, ':guid' => $guid]);
|
|
|
/** @var list<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}> $res */
|
|
|
+ * is_read:int,is_favorite:int,tags:string,attributes:?string,content_length:int}> $res */
|
|
|
return isset($res[0]) ? FreshRSS_Entry::fromArray($res[0]) : null;
|
|
|
}
|
|
|
|
|
|
public function searchById(string $id): ?FreshRSS_Entry {
|
|
|
$content = static::isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content';
|
|
|
+ $contentLength = 'LENGTH(' . (static::isCompressed() ? 'content_bin' : 'content') . ') AS content_length';
|
|
|
$hash = static::sqlHexEncode('hash');
|
|
|
$sql = <<<SQL
|
|
|
-SELECT id, guid, title, author, {$content}, link, date, `lastSeen`, `lastUserModified`, {$hash} AS hash, is_read, is_favorite, id_feed, tags, attributes
|
|
|
+SELECT id, guid, title, author, {$content}, link, date, `lastSeen`, `lastUserModified`, {$hash} AS hash, is_read, is_favorite, id_feed, tags, attributes,
|
|
|
+ {$contentLength}
|
|
|
FROM `_entry` WHERE id=:id
|
|
|
SQL;
|
|
|
$res = $this->fetchAssoc($sql, [':id' => $id]);
|
|
|
- /** @var list<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}> $res */
|
|
|
+ /** @var list<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,content_length:int}> $res */
|
|
|
return isset($res[0]) ? FreshRSS_Entry::fromArray($res[0]) : null;
|
|
|
}
|
|
|
|
|
|
@@ -1256,7 +1260,7 @@ SQL;
|
|
|
/**
|
|
|
* @param numeric-string $id_min
|
|
|
* @param numeric-string $id_max
|
|
|
- * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified' $sort
|
|
|
+ * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified'|'length' $sort
|
|
|
* @param 'ASC'|'DESC' $order
|
|
|
* @param numeric-string $continuation_id
|
|
|
* @param list<string|int> $continuation_values
|
|
|
@@ -1324,12 +1328,13 @@ SQL;
|
|
|
$values[] = $id_min;
|
|
|
}
|
|
|
|
|
|
- if ($continuation_id !== '0' && in_array($sort, ['c.name', 'date', 'f.name', 'link', 'title', 'lastUserModified'], true)) {
|
|
|
+ if ($continuation_id !== '0' && in_array($sort, ['c.name', 'date', 'f.name', 'link', 'title', 'lastUserModified', 'length'], true)) {
|
|
|
$sign = $order === 'ASC' ? '>' : '<';
|
|
|
$orderBy = match ($sort) {
|
|
|
'c.name' => 'c.name',
|
|
|
'f.name' => 'f.name',
|
|
|
'lastUserModified' => $alias . '`lastUserModified`',
|
|
|
+ 'length' => 'LENGTH(' . $alias . (static::isCompressed() ? 'content_bin' : 'content') . ')',
|
|
|
default => $alias . $sort,
|
|
|
};
|
|
|
// Keyset pagination (Compatibility syntax due to poor performance of tuple syntax in MySQL https://bugs.mysql.com/bug.php?id=104128)
|
|
|
@@ -1367,7 +1372,7 @@ SQL;
|
|
|
* @param int $id category/feed/tag ID
|
|
|
* @param numeric-string $id_min
|
|
|
* @param numeric-string $id_max
|
|
|
- * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified' $sort
|
|
|
+ * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified'|'length' $sort
|
|
|
* @param 'ASC'|'DESC' $order
|
|
|
* @param numeric-string $continuation_id
|
|
|
* @param list<string|int> $continuation_values
|
|
|
@@ -1426,11 +1431,12 @@ SQL;
|
|
|
}
|
|
|
|
|
|
$order = in_array($order, ['ASC', 'DESC'], true) ? $order : 'DESC';
|
|
|
- $sort = in_array($sort, ['id', 'c.name', 'date', 'f.name', 'link', 'title', 'rand', 'lastUserModified'], true) ? $sort : 'id';
|
|
|
+ $sort = in_array($sort, ['id', 'c.name', 'date', 'f.name', 'link', 'title', 'rand', 'lastUserModified', 'length'], true) ? $sort : 'id';
|
|
|
$orderBy = match ($sort) {
|
|
|
'c.name' => 'c.name',
|
|
|
'f.name' => 'f.name',
|
|
|
'lastUserModified' => 'e.`lastUserModified`',
|
|
|
+ 'length' => 'LENGTH(e.' . (static::isCompressed() ? 'content_bin' : 'content') . ')',
|
|
|
'rand' => static::sqlRandom(),
|
|
|
default => 'e.' . $sort,
|
|
|
};
|
|
|
@@ -1460,7 +1466,7 @@ SQL;
|
|
|
* @param int $id category/feed/tag ID
|
|
|
* @param numeric-string $id_min
|
|
|
* @param numeric-string $id_max
|
|
|
- * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified' $sort
|
|
|
+ * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified'|'length' $sort
|
|
|
* @param 'ASC'|'DESC' $order
|
|
|
* @param numeric-string $continuation_id
|
|
|
* @param list<string|int> $continuation_values
|
|
|
@@ -1470,7 +1476,7 @@ SQL;
|
|
|
string $id_min = '0', string $id_max = '0', string $sort = 'id', string $order = 'DESC',
|
|
|
string $continuation_id = '0', array $continuation_values = [], int $limit = 1, int $offset = 0): PDOStatement|false {
|
|
|
$order = in_array($order, ['ASC', 'DESC'], true) ? $order : 'DESC';
|
|
|
- $sort = in_array($sort, ['id', 'c.name', 'date', 'f.name', 'link', 'title', 'rand', 'lastUserModified'], true) ? $sort : 'id';
|
|
|
+ $sort = in_array($sort, ['id', 'c.name', 'date', 'f.name', 'link', 'title', 'rand', 'lastUserModified', 'length'], true) ? $sort : 'id';
|
|
|
|
|
|
[$values, $sql] = $this->sqlListWhere($type, $id, $state, $filters, id_min: $id_min, id_max: $id_max, sort: $sort, order: $order,
|
|
|
continuation_id: $continuation_id, continuation_values: $continuation_values, limit: $limit, offset: $offset);
|
|
|
@@ -1479,6 +1485,7 @@ SQL;
|
|
|
'c.name' => 'c0.name',
|
|
|
'f.name' => 'f0.name',
|
|
|
'lastUserModified' => 'e0.`lastUserModified`',
|
|
|
+ 'length' => 'LENGTH(e0.' . (static::isCompressed() ? 'content_bin' : 'content') . ')',
|
|
|
'rand' => static::sqlRandom(),
|
|
|
default => 'e0.' . $sort,
|
|
|
};
|
|
|
@@ -1523,7 +1530,7 @@ SQL;
|
|
|
* @param int $id category/feed/tag ID
|
|
|
* @param numeric-string $id_min
|
|
|
* @param numeric-string $id_max
|
|
|
- * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified' $sort
|
|
|
+ * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified'|'length' $sort
|
|
|
* @param 'ASC'|'DESC' $order
|
|
|
* @param numeric-string $continuation_id
|
|
|
* @param list<string|int> $continuation_values
|