From 9e5b9f023d8c751f74b9bc718b987210e40704d5 Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Fri, 22 Aug 2025 12:01:56 +0000 Subject: [PATCH 1/3] fix(config,event): remove unused code from 93257f4 --- app/config.py | 3 +-- app/database/events.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/config.py b/app/config.py index 5e0fd1a..97f327c 100644 --- a/app/config.py +++ b/app/config.py @@ -58,7 +58,7 @@ class StorageServiceType(str, Enum): class Settings(BaseSettings): - model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8") + model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="allow") # 数据库设置 mysql_host: str = "localhost" @@ -119,7 +119,6 @@ class Settings(BaseSettings): # 邮件服务设置 enable_email_verification: bool = Field(default=False, description="是否启用邮件验证功能") - enable_email_sending: bool = Field(default=False, description="是否真实发送邮件(false时仅模拟发送,输出到日志)") smtp_server: str = "localhost" smtp_port: int = 587 smtp_username: str = "" diff --git a/app/database/events.py b/app/database/events.py index 4f08372..2d346a6 100644 --- a/app/database/events.py +++ b/app/database/events.py @@ -41,7 +41,7 @@ class EventType(str, Enum): class Event(UTCBaseModel, SQLModel, table=True): __tablename__: str = "user_events" id: int = Field(default=None, primary_key=True) - created_at: datetime = Field(default_factory=utcnow, sa_column=Column(DateTime(timezone=True), default=utcnow)) + created_at: datetime = Field(default_factory=utcnow, sa_column=Column(DateTime(timezone=True))) type: EventType event_payload: dict = Field(exclude=True, default_factory=dict, sa_column=Column(JSON)) user_id: int | None = Field( From 32df7a4ce85824e0c73f1dbd06e2eada28c22893 Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Fri, 22 Aug 2025 12:40:22 +0000 Subject: [PATCH 2/3] fix(chat): missing greenlet when message is a command --- app/router/notification/message.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/router/notification/message.py b/app/router/notification/message.py index a323918..10fb6a3 100644 --- a/app/router/notification/message.py +++ b/app/router/notification/message.py @@ -90,6 +90,7 @@ async def send_message( channel_id = db_channel.channel_id channel_type = db_channel.type channel_name = db_channel.name + user_id = current_user.id # 使用 Redis 消息系统发送消息 - 立即返回 resp = await redis_message_system.send_message( @@ -114,7 +115,7 @@ async def send_message( message_id=resp.message_id, # 使用 Redis 系统生成的ID channel_id=channel_id, content=req.message, - sender_id=current_user.id, + sender_id=user_id, type=MessageType.ACTION if req.is_action else MessageType.PLAIN, uuid=req.uuid, ) From 2ac56ed3bf5c7bf490778a5d4cd664066ac37469 Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Fri, 22 Aug 2025 13:38:52 +0000 Subject: [PATCH 3/3] fix(daily-challenge): fix duplicated top 10%/50% placements --- app/database/daily_challenge.py | 2 + app/service/daily_challenge.py | 12 +++-- ...b22_daily_challenge_add_last_day_streak.py | 47 +++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 migrations/versions/178873984b22_daily_challenge_add_last_day_streak.py diff --git a/app/database/daily_challenge.py b/app/database/daily_challenge.py index 35127fa..19feb56 100644 --- a/app/database/daily_challenge.py +++ b/app/database/daily_challenge.py @@ -24,6 +24,7 @@ class DailyChallengeStatsBase(SQLModel, UTCBaseModel): daily_streak_best: int = Field(default=0) daily_streak_current: int = Field(default=0) last_update: datetime | None = Field(default=None, sa_column=Column(DateTime)) + last_day_streak: datetime | None = Field(default=None, sa_column=Column(DateTime)) last_weekly_streak: datetime | None = Field(default=None, sa_column=Column(DateTime)) playcount: int = Field(default=0) top_10p_placements: int = Field(default=0) @@ -103,4 +104,5 @@ async def process_daily_challenge_score(session: AsyncSession, user_id: int, roo else: stats.weekly_streak_current = 1 stats.last_update = now + stats.last_day_streak = now stats.last_weekly_streak = now diff --git a/app/service/daily_challenge.py b/app/service/daily_challenge.py index 13be1a4..d313921 100644 --- a/app/service/daily_challenge.py +++ b/app/service/daily_challenge.py @@ -156,13 +156,14 @@ async def process_daily_challenge_top(): stats = await session.get(DailyChallengeStats, score.user_id) if stats is None: # not execute return - - if total_score_count < 10 or ceil(i + 1 / total_score_count) <= 0.1: - stats.top_10p_placements += 1 - if total_score_count < 2 or ceil(i + 1 / total_score_count) <= 0.5: - stats.top_50p_placements += 1 + if stats.last_update is None or stats.last_update.replace(tzinfo=UTC).date() != now.date(): + if total_score_count < 10 or ceil(i + 1 / total_score_count) <= 0.1: + stats.top_10p_placements += 1 + if total_score_count < 2 or ceil(i + 1 / total_score_count) <= 0.5: + stats.top_50p_placements += 1 s.append(s) participated_users.append(score.user_id) + stats.last_update = now await session.commit() del s @@ -176,3 +177,4 @@ async def process_daily_challenge_top(): stats.last_weekly_streak.replace(tzinfo=UTC), now - timedelta(days=7) ): stats.weekly_streak_current = 0 + stats.last_update = now diff --git a/migrations/versions/178873984b22_daily_challenge_add_last_day_streak.py b/migrations/versions/178873984b22_daily_challenge_add_last_day_streak.py new file mode 100644 index 0000000..f488ded --- /dev/null +++ b/migrations/versions/178873984b22_daily_challenge_add_last_day_streak.py @@ -0,0 +1,47 @@ +"""daily_challenge: add last_day_streak + +Revision ID: 178873984b22 +Revises: 5b76689f6e4b +Create Date: 2025-08-22 13:34:31.282236 + +""" + +from __future__ import annotations + +from collections.abc import Sequence + +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision: str = "178873984b22" +down_revision: str | Sequence[str] | None = "5b76689f6e4b" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + """Upgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "daily_challenge_stats", + "last_update", + new_column_name="last_day_streak", + existing_type=sa.DateTime(), + nullable=True, + ) + op.add_column("daily_challenge_stats", sa.Column("last_update", sa.DateTime(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column( + "daily_challenge_stats", + "last_update", + existing_type=sa.DateTime(), + nullable=True, + ) + op.alter_column("daily_challenge_stats", "last_day_streak", new_column_name="last_update") + # ### end Alembic commands ###