1
0
mirror of synced 2024-11-27 23:40:48 +01:00

mai2: fix GetUserMusicApi pagination

This commit is contained in:
Kevin Trocolli 2023-06-13 22:07:48 -04:00
parent a0b25e2b7b
commit 5ca16f2067
2 changed files with 22 additions and 11 deletions

View File

@ -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,

View File

@ -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_(