diff --git a/titles/mai2/base.py b/titles/mai2/base.py index 44ec60d..1bba918 100644 --- a/titles/mai2/base.py +++ b/titles/mai2/base.py @@ -646,21 +646,30 @@ class Mai2Base: return {"userId": data["userId"], "length": 0, "userRegionList": []} def handle_get_user_music_api_request(self, data: Dict) -> Dict: - songs = self.data.score.get_best_scores(data["userId"]) + songs = self.data.score.get_best_scores(data.get("userId", 0)) + if songs is None: + return { + "userId": data["userId"], + "nextIndex": 0, + "userMusicList": [], + } + music_detail_list = [] - next_index = 0 + next_index = data.get("nextIndex", 0) + max_ct = data.get("maxCount", 50) + upper_lim = next_index + max_ct + num_user_songs = len(songs) - if songs is not None: - for song in songs: - tmp = song._asdict() - tmp.pop("id") - tmp.pop("user") - music_detail_list.append(tmp) + for x in range(next_index, upper_lim): + if num_user_songs >= x: + break - if len(music_detail_list) == data["maxCount"]: - next_index = data["maxCount"] + data["nextIndex"] - break + tmp = songs[x]._asdict() + tmp.pop("id") + tmp.pop("user") + music_detail_list.append(tmp) + next_index = 0 if len(music_detail_list) < max_ct else upper_lim return { "userId": data["userId"], "nextIndex": next_index, diff --git a/titles/mai2/schema/score.py b/titles/mai2/schema/score.py index 0f7f239..85dff16 100644 --- a/titles/mai2/schema/score.py +++ b/titles/mai2/schema/score.py @@ -7,6 +7,7 @@ from sqlalchemy.engine import Row from sqlalchemy.dialects.mysql import insert from core.data.schema import BaseData, metadata +from core.data import cached best_score = Table( "mai2_score_best", @@ -190,6 +191,7 @@ class Mai2ScoreData(BaseData): return None return result.lastrowid + @cached(2) def get_best_scores(self, user_id: int, song_id: int = None) -> Optional[List[Row]]: sql = best_score.select( and_(