1
0
forked from Hay1tsme/artemis

mai2: fix GetUserMusicApi pagination

This commit is contained in:
Hay1tsme 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": []} return {"userId": data["userId"], "length": 0, "userRegionList": []}
def handle_get_user_music_api_request(self, data: Dict) -> Dict: 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))
music_detail_list = [] if songs is None:
next_index = 0 return {
"userId": data["userId"],
"nextIndex": 0,
"userMusicList": [],
}
if songs is not None: music_detail_list = []
for song in songs: next_index = data.get("nextIndex", 0)
tmp = song._asdict() max_ct = data.get("maxCount", 50)
upper_lim = next_index + max_ct
num_user_songs = len(songs)
for x in range(next_index, upper_lim):
if num_user_songs >= x:
break
tmp = songs[x]._asdict()
tmp.pop("id") tmp.pop("id")
tmp.pop("user") tmp.pop("user")
music_detail_list.append(tmp) music_detail_list.append(tmp)
if len(music_detail_list) == data["maxCount"]: next_index = 0 if len(music_detail_list) < max_ct else upper_lim
next_index = data["maxCount"] + data["nextIndex"]
break
return { return {
"userId": data["userId"], "userId": data["userId"],
"nextIndex": next_index, "nextIndex": next_index,

View File

@ -7,6 +7,7 @@ from sqlalchemy.engine import Row
from sqlalchemy.dialects.mysql import insert from sqlalchemy.dialects.mysql import insert
from core.data.schema import BaseData, metadata from core.data.schema import BaseData, metadata
from core.data import cached
best_score = Table( best_score = Table(
"mai2_score_best", "mai2_score_best",
@ -190,6 +191,7 @@ class Mai2ScoreData(BaseData):
return None return None
return result.lastrowid return result.lastrowid
@cached(2)
def get_best_scores(self, user_id: int, song_id: int = None) -> Optional[List[Row]]: def get_best_scores(self, user_id: int, song_id: int = None) -> Optional[List[Row]]:
sql = best_score.select( sql = best_score.select(
and_( and_(