Adjust hot topics limit and index hashtag name
This commit is contained in:
@@ -82,7 +82,7 @@ class Hashtag(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
type = db.Column(db.Integer, nullable=False) # 0: Submission, 1: Comment
|
type = db.Column(db.Integer, nullable=False) # 0: Submission, 1: Comment
|
||||||
target_id = db.Column(db.Integer, nullable=False)
|
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):
|
class DenyWord(db.Model):
|
||||||
__tablename__ = 'deny_words'
|
__tablename__ = 'deny_words'
|
||||||
@@ -524,6 +524,8 @@ def get_statics():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"code": 2003, "data": str(e)})
|
return jsonify({"code": 2003, "data": str(e)})
|
||||||
|
|
||||||
|
# 注意区分哦,这两个路由一个是通过页码获取10个投稿的列表,一个是通过id获取单个投稿详情
|
||||||
|
|
||||||
@app.route('/api/posts_info', methods=['GET'])
|
@app.route('/api/posts_info', methods=['GET'])
|
||||||
def get_posts_info():
|
def get_posts_info():
|
||||||
try:
|
try:
|
||||||
@@ -588,7 +590,7 @@ def get_hot_topics():
|
|||||||
rows = db.session.query(
|
rows = db.session.query(
|
||||||
Hashtag.name,
|
Hashtag.name,
|
||||||
db.func.count(Hashtag.name).label('count')
|
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]
|
data = [{"name": name, "count": int(count)} for name, count in rows]
|
||||||
return jsonify({"code": 1000, "data": {"list": data}})
|
return jsonify({"code": 1000, "data": {"list": data}})
|
||||||
|
|||||||
Reference in New Issue
Block a user