From fcc4b95f7af137ae477582a62b29a8a2bba301f1 Mon Sep 17 00:00:00 2001 From: LeonspaceX Date: Fri, 30 Jan 2026 16:19:59 +0800 Subject: [PATCH] Adjust hot topics limit and index hashtag name --- back/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/back/main.py b/back/main.py index 8516ffd..6d6e94a 100644 --- a/back/main.py +++ b/back/main.py @@ -82,7 +82,7 @@ class Hashtag(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) type = db.Column(db.Integer, nullable=False) # 0: Submission, 1: Comment target_id = db.Column(db.Integer, nullable=False) - name = db.Column(db.String(255), nullable=False) + name = db.Column(db.String(255), nullable=False, index=True) class DenyWord(db.Model): __tablename__ = 'deny_words' @@ -524,6 +524,8 @@ def get_statics(): except Exception as e: return jsonify({"code": 2003, "data": str(e)}) +# 注意区分哦,这两个路由一个是通过页码获取10个投稿的列表,一个是通过id获取单个投稿详情 + @app.route('/api/posts_info', methods=['GET']) def get_posts_info(): try: @@ -588,7 +590,7 @@ def get_hot_topics(): rows = db.session.query( Hashtag.name, db.func.count(Hashtag.name).label('count') - ).group_by(Hashtag.name).order_by(db.func.count(Hashtag.name).desc()).limit(5).all() + ).group_by(Hashtag.name).order_by(db.func.count(Hashtag.name).desc()).limit(3).all() data = [{"name": name, "count": int(count)} for name, count in rows] return jsonify({"code": 1000, "data": {"list": data}})