refactor(project): use unified utcnow

This commit is contained in:
MingxuanGame
2025-08-22 11:27:45 +00:00
parent da66420eaa
commit 9b00dbda28
49 changed files with 201 additions and 167 deletions

View File

@@ -7,7 +7,7 @@ import json
from app.dependencies.database import get_redis, get_redis_message
from app.log import logger
from app.utils import bg_tasks
from app.utils import bg_tasks, utcnow
from .router import router
@@ -74,7 +74,7 @@ async def get_server_stats() -> ServerStats:
registered_users=registered_count,
online_users=online_count,
playing_users=playing_count,
timestamp=datetime.utcnow(),
timestamp=utcnow(),
)
except Exception as e:
logger.error(f"Error getting server stats: {e}")
@@ -83,7 +83,7 @@ async def get_server_stats() -> ServerStats:
registered_users=0,
online_users=0,
playing_users=0,
timestamp=datetime.utcnow(),
timestamp=utcnow(),
)
@@ -158,7 +158,7 @@ async def get_stats_debug_info():
try:
from app.service.enhanced_interval_stats import EnhancedIntervalStatsManager
current_time = datetime.utcnow()
current_time = utcnow()
current_interval = await EnhancedIntervalStatsManager.get_current_interval_info()
interval_stats = await EnhancedIntervalStatsManager.get_current_interval_stats()
@@ -334,7 +334,7 @@ async def record_hourly_stats() -> None:
online_count = await _get_online_users_count(redis_async)
playing_count = await _get_playing_users_count(redis_async)
current_time = datetime.utcnow()
current_time = utcnow()
history_point = {
"timestamp": current_time.isoformat(),
"online_count": online_count,

View File

@@ -1,6 +1,5 @@
from __future__ import annotations
from datetime import UTC, datetime
import hashlib
from app.database.lazer_user import BASE_INCLUDES, User, UserResp
@@ -15,7 +14,7 @@ from app.models.notification import (
)
from app.router.notification import server
from app.storage.base import StorageService
from app.utils import check_image
from app.utils import check_image, utcnow
from .router import router
@@ -53,7 +52,7 @@ async def create_team(
check_image(flag, 2 * 1024 * 1024, 240, 120)
check_image(cover, 10 * 1024 * 1024, 3000, 2000)
now = datetime.now(UTC)
now = utcnow()
team = Team(name=name, short_name=short_name, leader_id=user_id, created_at=now)
session.add(team)
await session.commit()
@@ -196,7 +195,7 @@ async def request_join_team(
)
).first():
raise HTTPException(status_code=409, detail="Join request already exists")
team_request = TeamRequest(user_id=current_user.id, team_id=team_id, requested_at=datetime.now(UTC))
team_request = TeamRequest(user_id=current_user.id, team_id=team_id, requested_at=utcnow())
session.add(team_request)
await session.commit()
await session.refresh(team_request)
@@ -233,7 +232,7 @@ async def handle_request(
if (await session.exec(select(exists()).where(TeamMember.user_id == user_id))).first():
raise HTTPException(status_code=409, detail="User is already a member of the team")
session.add(TeamMember(user_id=user_id, team_id=team_id, joined_at=datetime.now(UTC)))
session.add(TeamMember(user_id=user_id, team_id=team_id, joined_at=utcnow()))
await server.new_private_notification(TeamApplicationAccept.init(team_request))
else:

View File

@@ -1,13 +1,12 @@
from __future__ import annotations
from datetime import UTC, datetime
from app.auth import validate_username
from app.config import settings
from app.database.events import Event, EventType
from app.database.lazer_user import User
from app.dependencies.database import Database
from app.dependencies.user import get_client_user
from app.utils import utcnow
from .router import router
@@ -47,7 +46,7 @@ async def user_rename(
current_user.username = new_name
current_user.previous_usernames = previous_username
rename_event = Event(
created_at=datetime.now(UTC),
created_at=utcnow(),
type=EventType.USERNAME_CHANGE,
user_id=current_user.id,
user=current_user,