From edc68921c9ad847398a527e8f9124b0f22cd9c55 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Wed, 1 Mar 2023 23:24:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B6=88=E6=81=AF=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/chat_history.py | 20 +++++++++++--------- models/group_member_info.py | 7 +++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/models/chat_history.py b/models/chat_history.py index b91775e4..f30f325b 100644 --- a/models/chat_history.py +++ b/models/chat_history.py @@ -43,10 +43,13 @@ class ChatHistory(Model): :param order: 排序类型,desc,des :param date_scope: 日期范围 """ + o = "-" if order == "DESC" else "" + query = cls.filter(group_id=gid) + if date_scope: + query = query.filter(create_time__range=date_scope) return list( - await cls.filter(group_id=gid, create_time__range=date_scope) - .annotate(count=Count("user_qq")) - .order_by(order) + await query.annotate(count=Count("user_qq")) + .order_by(o + "count") .group_by("user_qq") .limit(limit) .values_list("user_qq", "count") @@ -107,9 +110,8 @@ class ChatHistory(Model): @classmethod async def _run_script(cls): - await cls.raw("alter table chat_history alter group_id drop not null;") - """允许 group_id 为空""" - await cls.raw("alter table chat_history alter text drop not null;") - """允许 text 为空""" - await cls.raw("alter table chat_history alter plain_text drop not null;") - """允许 plain_text 为空""" + return [ + "alter table chat_history alter group_id drop not null;", # 允许 group_id 为空 + "alter table chat_history alter text drop not null;", # 允许 text 为空 + "alter table chat_history alter plain_text drop not null;", # 允许 plain_text 为空 + ] diff --git a/models/group_member_info.py b/models/group_member_info.py index d374dc63..dd2820d7 100755 --- a/models/group_member_info.py +++ b/models/group_member_info.py @@ -105,7 +105,6 @@ class GroupInfoUser(Model): @classmethod async def _run_script(cls): - await cls.raw( - "alter table group_info_users alter user_join_time drop not null;" - ) - """允许 user_join_time 为空""" + return [ + "alter table group_info_users alter user_join_time drop not null;" # 允许 user_join_time 为空 + ]