From 00ac7edeb3630ca007ae53075b7698ab80265ad8 Mon Sep 17 00:00:00 2001 From: Jyong <76649700+JohnJyong@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:12:30 +0800 Subject: [PATCH] improve message clean logic (#11487) --- api/schedule/clean_messages.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/schedule/clean_messages.py b/api/schedule/clean_messages.py index 72ee2a8901af79..97e5c77e95361a 100644 --- a/api/schedule/clean_messages.py +++ b/api/schedule/clean_messages.py @@ -36,14 +36,16 @@ def clean_messages(): db.session.query(Message) .filter(Message.created_at < plan_sandbox_clean_message_day) .order_by(Message.created_at.desc()) - .paginate(page=page, per_page=100) + .limit(100) + .all() ) except NotFound: break - if messages.items is None or len(messages.items) == 0: + if not messages: break - for message in messages.items: + for message in messages: + plan_sandbox_clean_message_day = message.created_at app = App.query.filter_by(id=message.app_id).first() features_cache_key = f"features:{app.tenant_id}" plan_cache = redis_client.get(features_cache_key)