fix: 一尘看板按最新帖子发表时间排序 - 使用COALESCE(post_time, crawled_at)

This commit is contained in:
甲辰生产 2026-04-17 15:13:50 +08:00
parent 58c2291e83
commit 524601afc3
1 changed files with 2 additions and 2 deletions

View File

@ -138,13 +138,13 @@ def get_posts(
count_query = f"SELECT COUNT(*) FROM yichens_posts WHERE {where_sql}" count_query = f"SELECT COUNT(*) FROM yichens_posts WHERE {where_sql}"
total_count = db.execute(text(count_query), {k: v for k, v in params.items() if k not in ['limit', 'offset']}).scalar() or 0 total_count = db.execute(text(count_query), {k: v for k, v in params.items() if k not in ['limit', 'offset']}).scalar() or 0
# 查询数据 # 查询数据 - 有post_time时按post_time排序没有时按crawled_at排序
data_query = f""" data_query = f"""
SELECT post_id, title, content, category, post_type, price, SELECT post_id, title, content, category, post_type, price,
author_username, post_time, reply_count, view_count, url author_username, post_time, reply_count, view_count, url
FROM yichens_posts FROM yichens_posts
WHERE {where_sql} WHERE {where_sql}
ORDER BY post_time DESC LIMIT :limit OFFSET :offset ORDER BY COALESCE(post_time, crawled_at) DESC LIMIT :limit OFFSET :offset
""" """
results = db.execute(text(data_query), params).fetchall() results = db.execute(text(data_query), params).fetchall()