fix: prevent future article timestamps from pinning feeds

This commit is contained in:
hajimi
2026-08-03 23:46:38 +08:00
parent fabd378415
commit 450efec14d
6 changed files with 134 additions and 3 deletions
+16 -2
View File
@@ -97,12 +97,12 @@ class ArticleLists extends BaseApiDataLists implements ListsSearchInterface
*/
public function lists(): array
{
$orderRaw = 'published_at desc, id desc';
$orderRaw = $this->buildSafePublishedOrder();
$sortType = $this->params['sort'] ?? 'default';
$cid = (int) ($this->params['cid'] ?? 0);
// 最新排序
if ($sortType == 'new') {
$orderRaw = 'published_at desc, id desc';
$orderRaw = $this->buildSafePublishedOrder();
}
// 最热排序
if ($sortType == 'hot') {
@@ -140,6 +140,20 @@ class ArticleLists extends BaseApiDataLists implements ListsSearchInterface
}
/**
* 明显超前的脏发布时间不参与置顶排序,回退到文章入库时间。
*/
private function buildSafePublishedOrder(): string
{
return "CASE
WHEN published_at REGEXP '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$'
AND STR_TO_DATE(published_at, '%Y-%m-%d %H:%i:%s') <= DATE_ADD(NOW(), INTERVAL 2 DAY)
THEN STR_TO_DATE(published_at, '%Y-%m-%d %H:%i:%s')
ELSE FROM_UNIXTIME(create_time)
END DESC, id DESC";
}
/**
* @notes 获取文章数量
* @return int