Deduplicate rating list functions
This commit is contained in:
parent
5c48edc86b
commit
ecebd5d774
|
@ -924,26 +924,16 @@ class ChuniBase:
|
|||
if "userRecentPlayerList" in upsert: # TODO: Seen in Air, maybe implement sometime
|
||||
for rp in upsert["userRecentPlayerList"]:
|
||||
pass
|
||||
|
||||
if "userRatingBaseList" in upsert:
|
||||
await self.data.profile.put_profile_rating_best(
|
||||
|
||||
for rating_type in {"userRatingBaseList", "userRatingBaseHotList", "userRatingBaseNextList"}:
|
||||
if rating_type not in upsert:
|
||||
continue
|
||||
|
||||
await self.data.profile.put_profile_rating(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseHotList" in upsert:
|
||||
await self.data.profile.put_profile_rating_hot(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseHotList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseNextList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseNextList"]
|
||||
rating_type,
|
||||
upsert[rating_type],
|
||||
)
|
||||
|
||||
return {"returnCode": "1"}
|
||||
|
|
|
@ -734,7 +734,13 @@ class ChuniProfileData(BaseData):
|
|||
"total_play_count": total_play_count
|
||||
}
|
||||
|
||||
async def _put_profile_rating(self, rating_type: str, aime_id: int, version: int, rating_data: List[Dict]):
|
||||
async def put_profile_rating(
|
||||
self,
|
||||
aime_id: int,
|
||||
version: int,
|
||||
rating_type: str,
|
||||
rating_data: List[Dict],
|
||||
):
|
||||
inserted_values = [
|
||||
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
||||
for (i, x) in enumerate(rating_data)
|
||||
|
@ -746,33 +752,8 @@ class ChuniProfileData(BaseData):
|
|||
|
||||
if result is None:
|
||||
self.logger.warn(
|
||||
f"put_profile_rating_{rating_type}: Could not insert rating entries, aime_id: {aime_id}",
|
||||
f"put_profile_rating: Could not insert {rating_type}, aime_id: {aime_id}",
|
||||
)
|
||||
return
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
async def put_profile_rating_best(self, aime_id: int, version: int, rating_best_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"best",
|
||||
aime_id,
|
||||
version,
|
||||
rating_best_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_hot(self, aime_id: int, version: int, rating_hot_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"hot",
|
||||
aime_id,
|
||||
version,
|
||||
rating_hot_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next(self, aime_id: int, version: int, rating_next_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_data,
|
||||
)
|
||||
|
||||
|
|
|
@ -1067,47 +1067,23 @@ class OngekiBase:
|
|||
if "userKopList" in upsert:
|
||||
for x in upsert["userKopList"]:
|
||||
await self.data.profile.put_kop(user_id, x)
|
||||
|
||||
if "userRatingBaseBestList" in upsert:
|
||||
await self.data.profile.put_profile_rating_best(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseBestList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseBestNewList" in upsert:
|
||||
await self.data.profile.put_profile_rating_best_new(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseBestNewList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseHotList" in upsert:
|
||||
await self.data.profile.put_profile_rating_hot(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseHotList"]
|
||||
)
|
||||
|
||||
for rating_type in {
|
||||
"userRatingBaseBestList",
|
||||
"userRatingBaseBestNewList",
|
||||
"userRatingBaseHotList",
|
||||
"userRatingBaseNextList",
|
||||
"userRatingBaseNextNewList",
|
||||
"userRatingBaseHotNextList",
|
||||
}:
|
||||
if rating_type not in upsert:
|
||||
continue
|
||||
|
||||
if "userRatingBaseNextList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next(
|
||||
await self.data.profile.put_profile_rating(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseNextList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseNextNewList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next_new(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseNextNewList"]
|
||||
)
|
||||
|
||||
if "userRatingBaseHotNextList" in upsert:
|
||||
await self.data.profile.put_profile_rating_next_hot(
|
||||
user_id,
|
||||
self.version,
|
||||
upsert["userRatingBaseHotNextList"]
|
||||
rating_type,
|
||||
upsert[rating_type],
|
||||
)
|
||||
|
||||
return {"returnCode": 1, "apiName": "upsertUserAll"}
|
||||
|
|
|
@ -528,6 +528,7 @@ class OngekiProfileData(BaseData):
|
|||
)
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
async def delete_rival(self, aime_id: int, rival_id: int) -> Optional[int]:
|
||||
sql = delete(rival).where(rival.c.user==aime_id, rival.c.rivalUserId==rival_id)
|
||||
result = await self.execute(sql)
|
||||
|
@ -536,7 +537,13 @@ class OngekiProfileData(BaseData):
|
|||
else:
|
||||
return result.rowcount
|
||||
|
||||
async def _put_profile_rating(self, rating_type: str, aime_id: int, version: int, rating_data: List[Dict]):
|
||||
async def put_profile_rating(
|
||||
self,
|
||||
aime_id: int,
|
||||
version: int,
|
||||
rating_type: str,
|
||||
rating_data: List[Dict],
|
||||
):
|
||||
inserted_values = [
|
||||
{"user": aime_id, "version": version, "type": rating_type, "index": i, **x}
|
||||
for (i, x) in enumerate(rating_data)
|
||||
|
@ -553,51 +560,3 @@ class OngekiProfileData(BaseData):
|
|||
return
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
async def put_profile_rating_best(self, aime_id: int, version: int, rating_best_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"best",
|
||||
aime_id,
|
||||
version,
|
||||
rating_best_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_best_new(self, aime_id: int, version: int, rating_best_new_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"best_new",
|
||||
aime_id,
|
||||
version,
|
||||
rating_best_new_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_hot(self, aime_id: int, version: int, rating_hot_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"hot",
|
||||
aime_id,
|
||||
version,
|
||||
rating_hot_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next(self, aime_id: int, version: int, rating_next_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next_new(self, aime_id: int, version: int, rating_next_new_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next_new",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_new_data,
|
||||
)
|
||||
|
||||
async def put_profile_rating_next_hot(self, aime_id: int, version: int, rating_next_hot_data: List[Dict]):
|
||||
return await self._put_profile_rating(
|
||||
"next_hot",
|
||||
aime_id,
|
||||
version,
|
||||
rating_next_hot_data,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue