This commit is contained in:
咕谷酱
2025-08-22 22:03:55 +08:00
6 changed files with 60 additions and 9 deletions

View File

@@ -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 = ""

View File

@@ -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

View File

@@ -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(

View File

@@ -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,
)

View File

@@ -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

View File

@@ -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 ###