From 342eaa9a9795389cbfb0d81684875bc68a6c15fb Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Thu, 9 Sep 2021 16:02:12 +0800 Subject: [PATCH] Update pixiv.py --- models/pixiv.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/models/pixiv.py b/models/pixiv.py index 328be221..6210f2a2 100644 --- a/models/pixiv.py +++ b/models/pixiv.py @@ -159,11 +159,12 @@ class Pixiv(db.Model): 参数: :param tags: 关键词/Tag """ - query = cls.query + setattr(Pixiv, 'count', db.func.count(cls.pid).label('count')) + query = cls.select('count') if tags: for tag in tags: - query = cls.query.where(cls.tags.contains(tag)) - count = len(await query.where(cls.is_r18 == False).gino.all()) - r18_count = len(await query.where(cls.is_r18 == True).gino.all()) - return count, r18_count + query = query.where(cls.tags.contains(tag)) + count = await query.where(cls.is_r18 == False).gino.first() + r18_count = await query.where(cls.is_r18 == True).gino.first() + return count[0], r18_count[0]