fix(user): don't invalidate user cache when user is connecting to spectator-server

resolve the sixth of #90
This commit is contained in:
MingxuanGame
2025-12-06 21:28:39 +08:00
parent 36f5bd2ab3
commit a62ef049ff
5 changed files with 70 additions and 10 deletions

View File

@@ -90,6 +90,7 @@ class UserDict(TypedDict):
pm_friends_only: bool
profile_colour: str | None
username: str
is_online: bool
g0v0_playmode: GameMode
page: NotRequired[Page]
previous_usernames: NotRequired[list[str]]
@@ -154,7 +155,6 @@ class UserDict(TypedDict):
kudosu: NotRequired[Kudosu]
unread_pm_count: NotRequired[int]
default_group: NotRequired[str]
is_online: NotRequired[bool]
session_verified: NotRequired[bool]
session_verification_method: NotRequired[Literal["totp", "mail"] | None]
@@ -270,6 +270,7 @@ class UserModel(DatabaseModel[UserDict]):
is_active: bool = True
is_bot: bool = False
is_supporter: bool = False
is_online: bool = False
last_visit: datetime | None = Field(default_factory=utcnow, sa_column=Column(DateTime(timezone=True)))
pm_friends_only: bool = False
profile_colour: str | None = None
@@ -661,14 +662,6 @@ class UserModel(DatabaseModel[UserDict]):
async def default_group(_session: AsyncSession, obj: "User") -> str:
return "default" if not obj.is_bot else "bot"
@included
@staticmethod
async def is_online(_session: AsyncSession, obj: "User") -> bool:
from app.dependencies.database import get_redis
redis = get_redis()
return bool(await redis.exists(f"metadata:online:{obj.id}"))
@ondemand
@staticmethod
async def session_verified(