refactor(stats): remove stats manager

This commit is contained in:
MingxuanGame
2025-08-24 18:01:37 +00:00
parent bab6f843a5
commit d873c227c1
13 changed files with 12 additions and 1380 deletions

View File

@@ -87,11 +87,6 @@ class MetadataHub(Hub[MetadataClientState]):
async def _clean_state(self, state: MetadataClientState) -> None:
user_id = int(state.connection_id)
# Use centralized offline status management
from app.service.online_status_manager import online_status_manager
await online_status_manager.set_user_offline(user_id)
if state.pushable:
await asyncio.gather(*self.broadcast_tasks(user_id, None))
@@ -112,11 +107,6 @@ class MetadataHub(Hub[MetadataClientState]):
user_id = int(client.connection_id)
store = self.get_or_create_state(client)
# Use centralized online status management
from app.service.online_status_manager import online_status_manager
await online_status_manager.set_user_online(user_id, "metadata")
# CRITICAL FIX: Set online status IMMEDIATELY upon connection
# This matches the C# official implementation behavior
store.status = OnlineStatus.ONLINE

View File

@@ -163,11 +163,6 @@ class MultiplayerHub(Hub[MultiplayerClientState]):
async def _clean_state(self, state: MultiplayerClientState):
user_id = int(state.connection_id)
# Use centralized offline status management
from app.service.online_status_manager import online_status_manager
await online_status_manager.set_user_offline(user_id)
if state.room_id != 0 and state.room_id in self.rooms:
server_room = self.rooms[state.room_id]
room = server_room.room
@@ -179,11 +174,6 @@ class MultiplayerHub(Hub[MultiplayerClientState]):
"""Track online users when connecting to multiplayer hub"""
logger.info(f"[MultiplayerHub] Client {client.user_id} connected")
# Use centralized online status management
from app.service.online_status_manager import online_status_manager
await online_status_manager.set_user_online(client.user_id, "multiplayer")
def _ensure_in_room(self, client: Client) -> ServerMultiplayerRoom:
store = self.get_or_create_state(client)
if store.room_id == 0:

View File

@@ -31,7 +31,7 @@ from app.models.spectator_hub import (
StoreClientState,
StoreScore,
)
from app.utils import bg_tasks, unix_timestamp_to_windows
from app.utils import unix_timestamp_to_windows
from .hub import Client, Hub
@@ -160,12 +160,6 @@ class SpectatorHub(Hub[StoreClientState]):
Properly notifies watched users when spectator disconnects.
"""
user_id = int(state.connection_id)
# Use centralized offline status management
from app.service.online_status_manager import online_status_manager
await online_status_manager.set_user_offline(user_id)
if state.state:
await self._end_session(user_id, state.state, state)
@@ -183,11 +177,6 @@ class SpectatorHub(Hub[StoreClientState]):
"""
logger.info(f"[SpectatorHub] Client {client.user_id} connected")
# Use centralized online status management
from app.service.online_status_manager import online_status_manager
await online_status_manager.set_user_online(client.user_id, "spectator")
# Send all current player states to the new client
# This matches the official OnConnectedAsync behavior
active_states = []
@@ -281,9 +270,6 @@ class SpectatorHub(Hub[StoreClientState]):
logger.warning(f"[SpectatorHub] User {user_id} began new session without ending previous one; cleaning up")
try:
await self._end_session(user_id, store.state, store)
from app.router.private.stats import remove_playing_user
bg_tasks.add_task(remove_playing_user, user_id)
finally:
store.state = None
store.beatmap_status = None
@@ -320,19 +306,6 @@ class SpectatorHub(Hub[StoreClientState]):
)
logger.info(f"[SpectatorHub] {client.user_id} began playing {state.beatmap_id}")
# Track playing user and maintain online status
from app.router.private.stats import add_playing_user
from app.service.online_status_manager import online_status_manager
bg_tasks.add_task(add_playing_user, user_id)
# Critical fix: Maintain metadata online presence during gameplay
# This ensures the user appears online while playing
await online_status_manager.refresh_user_online_status(user_id, "playing")
# # 预缓存beatmap文件以加速后续PP计算
# await self._preload_beatmap_for_pp_calculation(state.beatmap_id)
await self.broadcast_group_call(
self.group_id(user_id),
"UserBeganPlaying",
@@ -346,12 +319,6 @@ class SpectatorHub(Hub[StoreClientState]):
if store.state is None or store.score is None:
return
# Critical fix: Refresh online status during active gameplay
# This prevents users from appearing offline while playing
from app.service.online_status_manager import online_status_manager
await online_status_manager.refresh_user_online_status(user_id, "playing_active")
header = frame_data.header
score_info = store.score.score_info
score_info.accuracy = header.accuracy
@@ -387,11 +354,6 @@ class SpectatorHub(Hub[StoreClientState]):
# End the play session and notify watchers
await self._end_session(user_id, state, store)
# Remove from playing user tracking
from app.router.private.stats import remove_playing_user
bg_tasks.add_task(remove_playing_user, user_id)
finally:
# CRITICAL FIX: Always clear state in finally block to ensure cleanup
# This matches the official C# implementation pattern

View File

@@ -9,6 +9,7 @@ import uuid
from app.database import User as DBUser
from app.dependencies import get_current_user
from app.dependencies.database import DBFactory, get_db_factory
from app.log import logger
from app.models.signalr import NegotiateResponse, Transport
from .hub import Hubs
@@ -18,6 +19,10 @@ from fastapi import APIRouter, Depends, Header, HTTPException, Query, WebSocket
from fastapi.security import SecurityScopes
router = APIRouter(prefix="/signalr", include_in_schema=False)
logger.warning(
"The Python version of SignalR server is deprecated. "
"Maybe it will be removed or be fixed to continuously use in the future"
)
@router.post("/{hub}/negotiate", response_model=NegotiateResponse)