perf: update_last_active_by_id via single UPDATE (#23215)
This commit is contained in:
@@ -588,18 +588,13 @@ class UsersTable:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@throttle(DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL)
|
@throttle(DATABASE_USER_ACTIVE_STATUS_UPDATE_INTERVAL)
|
||||||
def update_last_active_by_id(self, id: str, db: Optional[Session] = None) -> Optional[UserModel]:
|
def update_last_active_by_id(self, id: str, db: Optional[Session] = None) -> None:
|
||||||
try:
|
try:
|
||||||
with get_db_context(db) as db:
|
with get_db_context(db) as db:
|
||||||
user = db.query(User).filter_by(id=id).first()
|
db.query(User).filter_by(id=id).update({'last_active_at': int(time.time())})
|
||||||
if not user:
|
|
||||||
return None
|
|
||||||
user.last_active_at = int(time.time())
|
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(user)
|
|
||||||
return UserModel.model_validate(user)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
pass
|
||||||
|
|
||||||
def update_user_oauth_by_id(
|
def update_user_oauth_by_id(
|
||||||
self, id: str, provider: str, sub: str, db: Optional[Session] = None
|
self, id: str, provider: str, sub: str, db: Optional[Session] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user