Skip to content

Commit 674d6e0

Browse files
authored
Merge pull request open-webui#10809 from TobiasGoerke/feat/update_timestamp_asynchronously
feat: update get_current_user to refresh last active timestamp asynchronously
2 parents 20f0b02 + 76891f4 commit 674d6e0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

backend/open_webui/utils/auth.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from open_webui.constants import ERROR_MESSAGES
1717
from open_webui.env import WEBUI_SECRET_KEY, TRUSTED_SIGNATURE_KEY, STATIC_DIR, SRC_LOG_LEVELS
1818

19-
from fastapi import Depends, HTTPException, Request, Response, status
19+
from fastapi import BackgroundTasks, Depends, HTTPException, Request, Response, status
2020
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
2121
from passlib.context import CryptContext
2222

@@ -145,6 +145,7 @@ def get_http_authorization_cred(auth_header: str):
145145

146146
def get_current_user(
147147
request: Request,
148+
background_tasks: BackgroundTasks,
148149
auth_token: HTTPAuthorizationCredentials = Depends(bearer_security),
149150
):
150151
token = None
@@ -197,7 +198,9 @@ def get_current_user(
197198
detail=ERROR_MESSAGES.INVALID_TOKEN,
198199
)
199200
else:
200-
Users.update_user_last_active_by_id(user.id)
201+
# Refresh the user's last active timestamp asynchronously
202+
# to prevent blocking the request
203+
background_tasks.add_task(Users.update_user_last_active_by_id, user.id)
201204
return user
202205
else:
203206
raise HTTPException(

0 commit comments

Comments
 (0)