fix(score): fix score process

This commit is contained in:
MingxuanGame
2025-08-24 15:52:38 +00:00
parent 2f033f108a
commit 9d92fa0a68
3 changed files with 40 additions and 4 deletions

View File

@@ -94,6 +94,7 @@ class ScoreBase(AsyncAttrs, SQLModel, UTCBaseModel):
type: str
beatmap_id: int = Field(index=True, foreign_key="beatmaps.id")
maximum_statistics: ScoreStatistics = Field(sa_column=Column(JSON), default_factory=dict)
processed: bool = False # solo_score
@field_validator("maximum_statistics", mode="before")
@classmethod
@@ -211,7 +212,6 @@ class ScoreResp(ScoreBase):
is_perfect_combo: bool = False
legacy_perfect: bool = False
legacy_total_score: int = 0 # FIXME
processed: bool = True # solo_score
weight: float = 0.0
best_id: int | None = None
ruleset_id: int | None = None
@@ -865,6 +865,7 @@ async def process_score(
playlist_item_id=item_id,
room_id=room_id,
maximum_statistics=info.maximum_statistics,
processed=True,
)
if can_get_pp:
from app.calculator import pre_fetch_and_calculate_pp
@@ -892,5 +893,5 @@ async def process_score(
await session.refresh(score)
await session.refresh(score_token)
await session.refresh(user)
await redis.publish("score:processed", str(score.id or 0))
await redis.publish("osu-channel:score:processed", f'{{"ScoreId": {score.id}}}')
return score

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import json
from typing import TYPE_CHECKING
from app.database import PlaylistBestScore, Score
@@ -15,7 +16,7 @@ if TYPE_CHECKING:
from app.signalr.hub import MetadataHub
CHANNEL = "score:processed"
CHANNEL = "osu-channel:score:processed"
class ScoreSubscriber(RedisSubscriber):
@@ -79,6 +80,6 @@ class ScoreSubscriber(RedisSubscriber):
await self.metadata_hub.notify_room_score_processed(event)
async def _handler(self, channel: str, data: str):
score_id = int(data)
score_id = json.loads(data)["ScoreId"]
if self.metadata_hub:
await self._notify_room_score_processed(score_id)

View File

@@ -0,0 +1,34 @@
"""score: add processed
Revision ID: 34a563187e47
Revises: 3f890a76f036
Create Date: 2025-08-24 15:06:37.226068
"""
from __future__ import annotations
from collections.abc import Sequence
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = "34a563187e47"
down_revision: str | Sequence[str] | None = "3f890a76f036"
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.add_column("scores", sa.Column("processed", sa.Boolean(), nullable=False, default=1, server_default="1"))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("scores", "processed")
# ### end Alembic commands ###