diff --git a/backend/app/routers/yichens.py b/backend/app/routers/yichens.py index de8e152..a4b5ef4 100644 --- a/backend/app/routers/yichens.py +++ b/backend/app/routers/yichens.py @@ -138,13 +138,13 @@ def get_posts( 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 - # 查询数据 + # 查询数据 - 有post_time时按post_time排序,没有时按crawled_at排序 data_query = f""" SELECT post_id, title, content, category, post_type, price, author_username, post_time, reply_count, view_count, url FROM yichens_posts 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()