From 91de6d03fce4d6082359e7a1ba7e7f5ec02756b6 Mon Sep 17 00:00:00 2001 From: Fringg Date: Wed, 29 Apr 2026 06:46:02 +0300 Subject: [PATCH] fix: update cabinet_last_login on every request (throttled, 5 min) --- app/cabinet/dependencies.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/cabinet/dependencies.py b/app/cabinet/dependencies.py index 2d07d58f..b9557588 100644 --- a/app/cabinet/dependencies.py +++ b/app/cabinet/dependencies.py @@ -1,5 +1,7 @@ """FastAPI dependencies for cabinet module.""" +from datetime import UTC, datetime + import structlog from fastapi import Depends, HTTPException, Request, status from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer @@ -176,6 +178,15 @@ async def get_current_cabinet_user( }, ) + # Throttled update of cabinet_last_login (at most every 5 minutes) + now = datetime.now(UTC) + if not user.cabinet_last_login or (now - user.cabinet_last_login).total_seconds() > 300: + try: + user.cabinet_last_login = now + await db.commit() + except Exception: + pass + return user