feat(tags): add minimum vote count for top tags & provide official tags

Add configuration: `BEATMAP_TAG_TOP_COUNT` to control the minimun vote count

Tips: this is 10 in osu-web, but private server doesn't have enough player so we use 2 as default value

Official tags see: https://osu.ppy.sh/wiki/Beatmap/Beatmap_tags
This commit is contained in:
MingxuanGame
2025-09-14 05:21:48 +00:00
parent ad6bed4333
commit f4e6c3a58f
5 changed files with 775 additions and 0 deletions

View File

@@ -149,6 +149,7 @@ class Settings(BaseSettings):
enable_all_beatmap_leaderboard: bool = False
enable_all_beatmap_pp: bool = False
seasonal_backgrounds: Annotated[list[str], BeforeValidator(_parse_list)] = []
beatmap_tag_top_count: int = 2 # this is 10 in osu-web
# 谱面缓存设置
enable_beatmap_preload: bool = True

View File

@@ -206,11 +206,13 @@ class BeatmapResp(BeatmapBase):
select(BeatmapTagVote.tag_id, func.count().label("vote_count"))
.where(BeatmapTagVote.beatmap_id == beatmap.id)
.group_by(col(BeatmapTagVote.tag_id))
.having(func.count() > settings.beatmap_tag_top_count)
)
).all()
top_tag_ids: list[dict[str, int]] = []
for id, votes in all_votes:
top_tag_ids.append({"tag_id": id, "count": votes})
top_tag_ids.sort(key=lambda x: x["count"], reverse=True)
beatmap_["top_tag_ids"] = top_tag_ids
if user is not None:

View File

@@ -31,6 +31,7 @@ def load_tags() -> None:
logger.info(f"tag {ALL_TAGS[tag['id']].name} and tag {tag['name']} have the same tag id")
raise ValueError("duplicated tag id found")
ALL_TAGS[tag["id"]] = BeatmapTags.model_validate(tag)
logger.success(f"loaded {len(ALL_TAGS)} beatmap tags")
def get_tag_by_id(id: int) -> BeatmapTags: