From e6bfabcd1e07178d57b963b1fe80a92e79e859b2 Mon Sep 17 00:00:00 2001 From: chenovopride <1832292582@qq.com> Date: Wed, 6 Sep 2023 18:05:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E9=A2=9D=E5=BA=A6=E7=9A=84=E6=96=B9=E6=A1=88?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E7=AC=AC=E4=BA=8C=E5=A4=A9=E7=BB=A7?= =?UTF-8?q?=E6=89=BF=E4=B8=8A=E4=B8=80=E5=A4=A9=E6=B2=A1=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=AE=8C=E7=9A=84=E9=A2=9D=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/ratelimit.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/manager/ratelimit.py b/manager/ratelimit.py index 4f1554eb..b20a8041 100644 --- a/manager/ratelimit.py +++ b/manager/ratelimit.py @@ -62,7 +62,7 @@ def get_draw_usage(self, _type: str, _id: str) -> Document: # 初始化 if usage is None: - usage = {'type': _type, 'id': _id, 'count': 0, 'time': current_time} + usage = {'type': _type, 'id': _id, 'count': 0, 'time': current_time, 'day': current_day} self.draw_usage_db.insert(usage) return usage @@ -73,15 +73,18 @@ def get_usage(self, _type: str, _id: str) -> Document: q = Query() usage = self.usage_db.get(q.fragment({"type": _type, "id": _id})) current_time = time.localtime(time.time()).tm_hour + current_day = time.localtime(time.time()).tm_mday # 删除过期的记录 - if usage is not None and usage['time'] != current_time: + time_diff_dondition = (usage is not None and usage['time'] != current_time) + day_diff_condition = (usage is not None and usage['time'] == current_time and usage['day'] != current_day) + if time_diff_dondition or day_diff_condition: self.usage_db.remove(doc_ids=[usage.doc_id]) usage = None - + # 初始化 if usage is None: - usage = {'type': _type, 'id': _id, 'count': 0, 'time': current_time} + usage = {'type': _type, 'id': _id, 'count': 0, 'time': current_time, 'day': current_day} self.usage_db.insert(usage) return usage