push the same limit/offset changes for maimai and ongeki

This commit is contained in:
2024-11-15 21:36:16 +07:00
parent 37d07e6035
commit 2f59d7b0d6
12 changed files with 952 additions and 540 deletions

View File

@ -282,11 +282,11 @@ class ChuniBase:
max_ct = int(data["maxCount"])
# add one to the limit so we know if there's a next page of items
characters = await self.data.item.get_characters(
rows = await self.data.item.get_characters(
user_id, limit=max_ct + 1, offset=next_idx
)
if characters is None:
if rows is None or len(rows) == 0:
return {
"userId": user_id,
"length": 0,
@ -294,16 +294,16 @@ class ChuniBase:
"userCharacterList": [],
}
character_count = len(characters)
character_list = []
for x in range(min(character_count, max_ct)):
tmp = characters[x]._asdict()
tmp.pop("user")
for row in rows[:max_ct]:
tmp = row._asdict()
tmp.pop("id")
tmp.pop("user")
character_list.append(tmp)
if character_count > max_ct:
if len(rows) > max_ct:
next_idx += max_ct
else:
next_idx = -1
@ -357,8 +357,8 @@ class ChuniBase:
course_list = []
for x in range(min(len(rows), max_ct)):
tmp = rows[x]._asdict()
for row in rows[:max_ct]:
tmp = row._asdict()
tmp.pop("user")
tmp.pop("id")
course_list.append(tmp)
@ -438,14 +438,14 @@ class ChuniBase:
rival_levels = [int(x["level"]) for x in data["userRivalMusicLevelList"]]
# Fetch all the rival music entries for the user
music_detail_rows = await self.data.score.get_scores(
rows = await self.data.score.get_scores(
rival_id,
levels=rival_levels,
limit=max_ct + 1,
offset=next_idx,
)
if music_detail_rows is None or len(music_detail_rows) == 0:
if rows is None or len(rows) == 0:
return {
"userId": user_id,
"rivalId": rival_id,
@ -453,7 +453,7 @@ class ChuniBase:
"userRivalMusicList": [],
}
music_details = [x._asdict() for x in music_detail_rows]
music_details = [x._asdict() for x in rows]
returned_music_details_count = 0
music_list = []
@ -473,7 +473,7 @@ class ChuniBase:
# if we returned fewer PBs than we originally asked for from the database, that means
# we queried for the PBs of max_ct + 1 songs.
if returned_music_details_count < len(music_detail_rows):
if returned_music_details_count < len(rows):
next_idx += max_ct
else:
next_idx = -1
@ -497,7 +497,7 @@ class ChuniBase:
# still needs to be implemented on WebUI
# 1: Music, 2: User, 3: Character
fav_list = await self.data.item.get_all_favorites(
rows = await self.data.item.get_all_favorites(
user_id,
self.version,
fav_kind=kind,
@ -505,11 +505,11 @@ class ChuniBase:
offset=next_idx,
)
if fav_list is not None:
for fav in fav_list:
if rows is not None:
for fav in rows[:max_ct]:
user_fav_item_list.append({"id": fav["favId"]})
if fav_list is None or len(fav_list) <= max_ct:
if rows is None or len(rows) <= max_ct:
next_idx = -1
else:
next_idx += max_ct
@ -550,8 +550,8 @@ class ChuniBase:
items: List[Dict[str, Any]] = []
for i in range(min(len(rows), max_ct)):
tmp = rows[i]._asdict()
for row in rows[:max_ct]:
tmp = row._asdict()
tmp.pop("user")
tmp.pop("id")
items.append(tmp)