fix(score): fix score process
This commit is contained in:
@@ -94,6 +94,7 @@ class ScoreBase(AsyncAttrs, SQLModel, UTCBaseModel):
|
|||||||
type: str
|
type: str
|
||||||
beatmap_id: int = Field(index=True, foreign_key="beatmaps.id")
|
beatmap_id: int = Field(index=True, foreign_key="beatmaps.id")
|
||||||
maximum_statistics: ScoreStatistics = Field(sa_column=Column(JSON), default_factory=dict)
|
maximum_statistics: ScoreStatistics = Field(sa_column=Column(JSON), default_factory=dict)
|
||||||
|
processed: bool = False # solo_score
|
||||||
|
|
||||||
@field_validator("maximum_statistics", mode="before")
|
@field_validator("maximum_statistics", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -211,7 +212,6 @@ class ScoreResp(ScoreBase):
|
|||||||
is_perfect_combo: bool = False
|
is_perfect_combo: bool = False
|
||||||
legacy_perfect: bool = False
|
legacy_perfect: bool = False
|
||||||
legacy_total_score: int = 0 # FIXME
|
legacy_total_score: int = 0 # FIXME
|
||||||
processed: bool = True # solo_score
|
|
||||||
weight: float = 0.0
|
weight: float = 0.0
|
||||||
best_id: int | None = None
|
best_id: int | None = None
|
||||||
ruleset_id: int | None = None
|
ruleset_id: int | None = None
|
||||||
@@ -865,6 +865,7 @@ async def process_score(
|
|||||||
playlist_item_id=item_id,
|
playlist_item_id=item_id,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
maximum_statistics=info.maximum_statistics,
|
maximum_statistics=info.maximum_statistics,
|
||||||
|
processed=True,
|
||||||
)
|
)
|
||||||
if can_get_pp:
|
if can_get_pp:
|
||||||
from app.calculator import pre_fetch_and_calculate_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)
|
||||||
await session.refresh(score_token)
|
await session.refresh(score_token)
|
||||||
await session.refresh(user)
|
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
|
return score
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from app.database import PlaylistBestScore, Score
|
from app.database import PlaylistBestScore, Score
|
||||||
@@ -15,7 +16,7 @@ if TYPE_CHECKING:
|
|||||||
from app.signalr.hub import MetadataHub
|
from app.signalr.hub import MetadataHub
|
||||||
|
|
||||||
|
|
||||||
CHANNEL = "score:processed"
|
CHANNEL = "osu-channel:score:processed"
|
||||||
|
|
||||||
|
|
||||||
class ScoreSubscriber(RedisSubscriber):
|
class ScoreSubscriber(RedisSubscriber):
|
||||||
@@ -79,6 +80,6 @@ class ScoreSubscriber(RedisSubscriber):
|
|||||||
await self.metadata_hub.notify_room_score_processed(event)
|
await self.metadata_hub.notify_room_score_processed(event)
|
||||||
|
|
||||||
async def _handler(self, channel: str, data: str):
|
async def _handler(self, channel: str, data: str):
|
||||||
score_id = int(data)
|
score_id = json.loads(data)["ScoreId"]
|
||||||
if self.metadata_hub:
|
if self.metadata_hub:
|
||||||
await self._notify_room_score_processed(score_id)
|
await self._notify_room_score_processed(score_id)
|
||||||
|
|||||||
34
migrations/versions/34a563187e47_score_add_processed.py
Normal file
34
migrations/versions/34a563187e47_score_add_processed.py
Normal 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 ###
|
||||||
Reference in New Issue
Block a user