fix: 一尘看板按最新帖子发表时间排序 - 使用COALESCE(post_time, crawled_at)
This commit is contained in:
parent
58c2291e83
commit
524601afc3
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue