Adjust hot topics limit and index hashtag name

This commit is contained in:
LeonspaceX
2026-01-30 16:19:59 +08:00
parent c30803f073
commit fcc4b95f7a

View File

@@ -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}})