From 48b075d99d3eeba719a3b9403d9542a1ed0f6f70 Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Thu, 14 Aug 2025 07:01:41 +0000 Subject: [PATCH] feat(config): add `ENABLE_ALL_BEATMAP_PP` --- .env.example | 1 + README.md | 1 + app/config.py | 1 + app/database/score.py | 24 +++++++++--------------- app/router/v2/score.py | 12 ++++++++---- app/service/pp_recalculate.py | 5 +---- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.env.example b/.env.example index 1758417..67e0c2f 100644 --- a/.env.example +++ b/.env.example @@ -54,6 +54,7 @@ ENABLE_OSU_AP=false # 启用 osu!AP 统计数据 ENABLE_ALL_MODS_PP=false # 启用所有 Mod 的 PP 计算 ENABLE_SUPPORTER_FOR_ALL_USERS=false # 启用所有新注册用户的支持者状态 ENABLE_ALL_BEATMAP_LEADERBOARD=false # 启用所有谱面的排行榜(没有排行榜的谱面会以 APPROVED 状态返回) +ENABLE_ALL_BEATMAP_PP=false # 允许任何谱面获得 PP SEASONAL_BACKGROUNDS='[]' # 季节背景图 URL 列表 # 存储服务设置 diff --git a/README.md b/README.md index fe201e4..a48cd8a 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ Fetcher 用于从 osu! 官方 API 获取数据,使用 osu! 官方 API 的 OAut | `ENABLE_ALL_MODS_PP` | 启用所有 Mod 的 PP 计算 | `false` | | `ENABLE_SUPPORTER_FOR_ALL_USERS` | 启用所有新注册用户的支持者状态 | `false` | | `ENABLE_ALL_BEATMAP_LEADERBOARD` | 启用所有谱面的排行榜 | `false` | +| `ENABLE_ALL_BEATMAP_PP` | 允许任何谱面获得 PP | `false` | | `SEASONAL_BACKGROUNDS` | 季节背景图 URL 列表 | `[]` | ### 存储服务设置 diff --git a/app/config.py b/app/config.py index e99b080..83b87b5 100644 --- a/app/config.py +++ b/app/config.py @@ -93,6 +93,7 @@ class Settings(BaseSettings): enable_all_mods_pp: bool = False enable_supporter_for_all_users: bool = False enable_all_beatmap_leaderboard: bool = False + enable_all_beatmap_pp: bool = False seasonal_backgrounds: list[str] = [] # 存储设置 diff --git a/app/database/score.py b/app/database/score.py index bfc7840..3d1af05 100644 --- a/app/database/score.py +++ b/app/database/score.py @@ -531,7 +531,12 @@ async def get_user_best_pp( async def process_user( - session: AsyncSession, user: User, score: Score, length: int, ranked: bool = False + session: AsyncSession, + user: User, + score: Score, + length: int, + ranked: bool = False, + has_leaderboard: bool = False, ): assert user.id assert score.id @@ -598,18 +603,6 @@ async def process_user( statistics.grade_sh -= 1 case Rank.A: statistics.grade_a -= 1 - else: - previous_score_best = BestScore( - user_id=user.id, - beatmap_id=score.beatmap_id, - gamemode=score.gamemode, - score_id=score.id, - total_score=score.total_score, - rank=score.rank, - mods=mod_for_save, - ) - session.add(previous_score_best) - statistics.ranked_score += difference statistics.level_current = calculate_score_to_level(statistics.total_score) statistics.maximum_combo = max(statistics.maximum_combo, score.max_combo) @@ -666,7 +659,7 @@ async def process_user( }, } session.add(rank_lost_event) - if score.passed and ranked: + if score.passed and has_leaderboard: if previous_score_best_mod is not None: previous_score_best_mod.mods = mod_for_save previous_score_best_mod.score_id = score.id @@ -674,7 +667,7 @@ async def process_user( previous_score_best_mod.total_score = score.total_score elif ( previous_score_best is not None and previous_score_best.score_id != score.id - ): + ) or previous_score_best is None: session.add( BestScore( user_id=user.id, @@ -686,6 +679,7 @@ async def process_user( mods=mod_for_save, ) ) + statistics.play_count += 1 mouthly_playcount.count += 1 statistics.play_time += length diff --git a/app/router/v2/score.py b/app/router/v2/score.py index 0065d09..5743e5e 100644 --- a/app/router/v2/score.py +++ b/app/router/v2/score.py @@ -98,14 +98,16 @@ async def submit_score( db_beatmap = await Beatmap.get_or_fetch(db, fetcher, bid=beatmap) except HTTPError: raise HTTPException(status_code=404, detail="Beatmap not found") - ranked = ( - db_beatmap.beatmap_status.has_pp() | settings.enable_all_beatmap_leaderboard + has_pp = db_beatmap.beatmap_status.has_pp() | settings.enable_all_beatmap_pp + has_leaderboard = ( + db_beatmap.beatmap_status.has_leaderboard() + | settings.enable_all_beatmap_leaderboard ) beatmap_length = db_beatmap.total_length score = await process_score( current_user, beatmap, - ranked, + has_pp, score_token, info, fetcher, @@ -117,7 +119,9 @@ async def submit_score( await db.refresh(current_user) score_id = score.id score_token.score_id = score_id - await process_user(db, current_user, score, beatmap_length, ranked) + await process_user( + db, current_user, score, beatmap_length, has_pp, has_leaderboard + ) score = (await db.exec(select(Score).where(Score.id == score_id))).first() assert score is not None return await ScoreResp.from_db(db, score) diff --git a/app/service/pp_recalculate.py b/app/service/pp_recalculate.py index c6b2ad5..3f76dec 100644 --- a/app/service/pp_recalculate.py +++ b/app/service/pp_recalculate.py @@ -79,10 +79,7 @@ async def _recalculate_pp( time -= 1 await asyncio.sleep(2) continue - ranked = ( - db_beatmap.beatmap_status.has_pp() - | settings.enable_all_beatmap_leaderboard - ) + ranked = db_beatmap.beatmap_status.has_pp() | settings.enable_all_beatmap_pp if not ranked or not mods_can_get_pp( MODE_TO_INT[score.gamemode], score.mods ):