From b5ce13d1f103457a74d58eefca73fa0de9ca7b4b Mon Sep 17 00:00:00 2001 From: DSRLIN Date: Thu, 26 Oct 2023 05:37:11 +0000 Subject: [PATCH 1/2] fix chuni songlist duplicate songs and missing diff --- titles/chuni/base.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/titles/chuni/base.py b/titles/chuni/base.py index 775b09b..e8d19e2 100644 --- a/titles/chuni/base.py +++ b/titles/chuni/base.py @@ -10,7 +10,7 @@ from core.config import CoreConfig from titles.chuni.const import ChuniConstants from titles.chuni.database import ChuniData from titles.chuni.config import ChuniConfig - +SCORE_BUFFER = {} class ChuniBase: def __init__(self, core_cfg: CoreConfig, game_cfg: ChuniConfig) -> None: @@ -562,7 +562,7 @@ class ChuniBase: "userMapList": map_list, } - def handle_get_user_music_api_request(self, data: Dict) -> Dict: +def handle_get_user_music_api_request(self, data: Dict) -> Dict: music_detail = self.data.score.get_scores(data["userId"]) if music_detail is None: return { @@ -583,22 +583,39 @@ class ChuniBase: tmp.pop("id") for song in song_list: + score_buf = SCORE_BUFFER.get(str(data["userId"])) or [] if song["userMusicDetailList"][0]["musicId"] == tmp["musicId"]: found = True song["userMusicDetailList"].append(tmp) song["length"] = len(song["userMusicDetailList"]) + score_buf.append(tmp["musicId"]) + SCORE_BUFFER[str(data["userId"])] = score_buf - if not found: + score_buf = SCORE_BUFFER.get(str(data["userId"])) or [] + if not found and tmp["musicId"] not in score_buf: song_list.append({"length": 1, "userMusicDetailList": [tmp]}) + score_buf.append(tmp["musicId"]) + SCORE_BUFFER[str(data["userId"])] = score_buf if len(song_list) >= max_ct: break - - if len(music_detail) >= next_idx + max_ct: - next_idx += max_ct + + try: + while song_list[-1]["userMusicDetailList"][0]["musicId"] == music_detail[x + 1]["musicId"]: + music = music_detail[x + 1]._asdict() + music.pop("user") + music.pop("id") + song_list[-1]["userMusicDetailList"].append(music) + song_list[-1]["length"] += 1 + x += 1 + except IndexError: + pass + + if len(song_list) >= max_ct: + next_idx += len(song_list) else: next_idx = -1 - + SCORE_BUFFER[str(data["userId"])] = [] return { "userId": data["userId"], "length": len(song_list), From 3259552c297c5eec975f8ec1628aa32c91aa659f Mon Sep 17 00:00:00 2001 From: DSRLIN Date: Thu, 26 Oct 2023 05:38:33 +0000 Subject: [PATCH 2/2] update bug --- titles/chuni/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/titles/chuni/base.py b/titles/chuni/base.py index e8d19e2..29c924d 100644 --- a/titles/chuni/base.py +++ b/titles/chuni/base.py @@ -562,7 +562,7 @@ class ChuniBase: "userMapList": map_list, } -def handle_get_user_music_api_request(self, data: Dict) -> Dict: + def handle_get_user_music_api_request(self, data: Dict) -> Dict: music_detail = self.data.score.get_scores(data["userId"]) if music_detail is None: return {