From 48eb59006534a0fd89e1e64eebce1747f91b88b3 Mon Sep 17 00:00:00 2001 From: takatost Date: Fri, 1 Sep 2023 13:58:26 +0800 Subject: [PATCH] feat: optimize last_active_at update (#1083) --- api/app.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/app.py b/api/app.py index 4a10212f6..6fe62ca2d 100644 --- a/api/app.py +++ b/api/app.py @@ -1,6 +1,6 @@ # -*- coding:utf-8 -*- import os -from datetime import datetime +from datetime import datetime, timedelta from werkzeug.exceptions import Forbidden @@ -145,8 +145,12 @@ def load_user(user_id): _create_tenant_for_account(account) session['workspace_id'] = account.current_tenant_id - account.last_active_at = datetime.utcnow() - db.session.commit() + current_time = datetime.utcnow() + + # update last_active_at when last_active_at is more than 10 minutes ago + if current_time - account.last_active_at > timedelta(minutes=10): + account.last_active_at = current_time + db.session.commit() # Log in the user with the updated user_id flask_login.login_user(account, remember=True)