forked from Hay1tsme/artemis
mai2: fix GetUserMusicApi pagination
This commit is contained in:
parent
a0b25e2b7b
commit
5ca16f2067
@ -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))
|
||||||
|
if songs is None:
|
||||||
|
return {
|
||||||
|
"userId": data["userId"],
|
||||||
|
"nextIndex": 0,
|
||||||
|
"userMusicList": [],
|
||||||
|
}
|
||||||
|
|
||||||
music_detail_list = []
|
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 x in range(next_index, upper_lim):
|
||||||
for song in songs:
|
if num_user_songs >= x:
|
||||||
tmp = song._asdict()
|
break
|
||||||
tmp.pop("id")
|
|
||||||
tmp.pop("user")
|
|
||||||
music_detail_list.append(tmp)
|
|
||||||
|
|
||||||
if len(music_detail_list) == data["maxCount"]:
|
tmp = songs[x]._asdict()
|
||||||
next_index = data["maxCount"] + data["nextIndex"]
|
tmp.pop("id")
|
||||||
break
|
tmp.pop("user")
|
||||||
|
music_detail_list.append(tmp)
|
||||||
|
|
||||||
|
next_index = 0 if len(music_detail_list) < max_ct else upper_lim
|
||||||
return {
|
return {
|
||||||
"userId": data["userId"],
|
"userId": data["userId"],
|
||||||
"nextIndex": next_index,
|
"nextIndex": next_index,
|
||||||
|
@ -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_(
|
||||||
|
Loading…
Reference in New Issue
Block a user