From be293c736f794fb188521e580e7372cf16c21888 Mon Sep 17 00:00:00 2001 From: hole-thu Date: Wed, 15 Dec 2021 20:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hole.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hole.py b/hole.py index b2962cb..d8f89f9 100644 --- a/hole.py +++ b/hole.py @@ -357,15 +357,23 @@ def attention(): def get_attention(): u = require_token() - ats = Attention.query.filter_by( - name_hash=hash_name( - u.name), disabled=False) + ats = Attention.query.with_entities( + Attention.pid + ).filter_by( + name_hash=hash_name(u.name), disabled=False + ).all() - posts = [Post.query.get(at.pid) for at in ats.all()] - data = [map_post(post, u.name, 10) - for post in posts[::-1] - if post and not post.deleted - ] + pids = [pid for pid, in ats] or [0] # sql not allow empty in + posts = Post.query.filter( + Post.id.in_(pids) + ).filter_by( + deleted=False + ).order_by(Post.id.desc()).all() + + data = [ + map_post(post, u.name, 10) + for post in posts + ] return { 'code': 0,