move to async database

This commit is contained in:
2024-01-09 14:42:17 -05:00
parent edd3ce8ead
commit 05586df08a
77 changed files with 1925 additions and 1948 deletions

View File

@ -157,7 +157,7 @@ class OngekiBase:
return {"type": data["type"], "length": 0, "gameIdlistList": []}
async def handle_get_game_ranking_api_request(self, data: Dict) -> Dict:
game_ranking_list = self.data.static.get_ranking_list(self.version)
game_ranking_list = await self.data.static.get_ranking_list(self.version)
ranking_list = []
for music in game_ranking_list:
@ -172,13 +172,13 @@ class OngekiBase:
}
async def handle_get_game_point_api_request(self, data: Dict) -> Dict:
get_game_point = self.data.static.get_static_game_point()
get_game_point = await self.data.static.get_static_game_point()
game_point = []
if not get_game_point:
self.logger.info(f"GP table is empty, inserting defaults")
self.data.static.put_static_game_point_defaults()
get_game_point = self.data.static.get_static_game_point()
await self.data.static.put_static_game_point_defaults()
get_game_point = await self.data.static.get_static_game_point()
for gp in get_game_point:
tmp = gp._asdict()
game_point.append(tmp)
@ -204,7 +204,7 @@ class OngekiBase:
return {"returnCode": 1, "apiName": "ExtendLockTimeApi"}
async def handle_get_game_reward_api_request(self, data: Dict) -> Dict:
get_game_rewards = self.data.static.get_reward_list(self.version)
get_game_rewards = await self.data.static.get_reward_list(self.version)
reward_list = []
for reward in get_game_rewards:
@ -222,7 +222,7 @@ class OngekiBase:
}
async def handle_get_game_present_api_request(self, data: Dict) -> Dict:
get_present = self.data.static.get_present_list(self.version)
get_present = await self.data.static.get_present_list(self.version)
present_list = []
for present in get_present:
@ -245,7 +245,7 @@ class OngekiBase:
return {"length": 0, "gameSaleList": []}
async def handle_get_game_tech_music_api_request(self, data: Dict) -> Dict:
music_list = self.data.static.get_tech_music(self.version)
music_list = await self.data.static.get_tech_music(self.version)
prep_music_list = []
for music in music_list:
@ -268,9 +268,9 @@ class OngekiBase:
client_id = data["clientId"]
client_setting_data = data["clientSetting"]
cab = self.data.arcade.get_machine(client_id)
cab = await self.data.arcade.get_machine(client_id)
if cab is not None:
self.data.static.put_client_setting_data(cab['id'], client_setting_data)
await self.data.static.put_client_setting_data(cab['id'], client_setting_data)
return {"returnCode": 1, "apiName": "UpsertClientSettingApi"}
async def handle_upsert_client_testmode_api_request(self, data: Dict) -> Dict:
@ -279,7 +279,7 @@ class OngekiBase:
region_id = data["regionId"]
client_testmode_data = data["clientTestmode"]
self.data.static.put_client_testmode_data(region_id, client_testmode_data)
await self.data.static.put_client_testmode_data(region_id, client_testmode_data)
return {"returnCode": 1, "apiName": "UpsertClientTestmodeApi"}
async def handle_upsert_client_bookkeeping_api_request(self, data: Dict) -> Dict:
@ -296,7 +296,7 @@ class OngekiBase:
if user >= 200000000000000: # Account for guest play
user = None
self.data.log.put_gp_log(
await self.data.log.put_gp_log(
user,
data["usedCredit"],
data["placeName"],
@ -313,7 +313,7 @@ class OngekiBase:
return {"returnCode": 1, "apiName": "ExtendLockTimeApi"}
async def handle_get_game_event_api_request(self, data: Dict) -> Dict:
evts = self.data.static.get_enabled_events(self.version)
evts = await self.data.static.get_enabled_events(self.version)
if evts is None:
return {
@ -366,7 +366,7 @@ class OngekiBase:
return {"userId": data["userId"], "length": 0, "userRegionList": []}
async def handle_get_user_preview_api_request(self, data: Dict) -> Dict:
profile = self.data.profile.get_profile_preview(data["userId"], self.version)
profile = await self.data.profile.get_profile_preview(data["userId"], self.version)
if profile is None:
return {
@ -422,7 +422,7 @@ class OngekiBase:
Gets the number of AB and ABPs a player has per-difficulty (7, 7+, 8, etc)
The game sends this in upsert so we don't have to calculate it all out thankfully
"""
utcl = self.data.score.get_tech_count(data["userId"])
utcl = await self.data.score.get_tech_count(data["userId"])
userTechCountList = []
for tc in utcl:
@ -437,7 +437,7 @@ class OngekiBase:
}
async def handle_get_user_tech_event_api_request(self, data: Dict) -> Dict:
user_tech_event_list = self.data.item.get_tech_event(self.version, data["userId"])
user_tech_event_list = await self.data.item.get_tech_event(self.version, data["userId"])
if user_tech_event_list is None:
return {}
@ -456,7 +456,7 @@ class OngekiBase:
}
async def handle_get_user_tech_event_ranking_api_request(self, data: Dict) -> Dict:
user_tech_event_ranks = self.data.item.get_tech_event_ranking(self.version, data["userId"])
user_tech_event_ranks = await self.data.item.get_tech_event_ranking(self.version, data["userId"])
if user_tech_event_ranks is None:
return {
"userId": data["userId"],
@ -482,7 +482,7 @@ class OngekiBase:
}
async def handle_get_user_kop_api_request(self, data: Dict) -> Dict:
kop_list = self.data.profile.get_kop(data["userId"])
kop_list = await self.data.profile.get_kop(data["userId"])
if kop_list is None:
return {}
@ -518,7 +518,7 @@ class OngekiBase:
async def handle_get_user_item_api_request(self, data: Dict) -> Dict:
kind = data["nextIndex"] / 10000000000
p = self.data.item.get_items(data["userId"], kind)
p = await self.data.item.get_items(data["userId"], kind)
if p is None:
return {
@ -553,7 +553,7 @@ class OngekiBase:
}
async def handle_get_user_option_api_request(self, data: Dict) -> Dict:
o = self.data.profile.get_profile_options(data["userId"])
o = await self.data.profile.get_profile_options(data["userId"])
if o is None:
return {}
@ -567,11 +567,11 @@ class OngekiBase:
return {"userId": data["userId"], "userOption": user_opts}
async def handle_get_user_data_api_request(self, data: Dict) -> Dict:
p = self.data.profile.get_profile_data(data["userId"], self.version)
p = await self.data.profile.get_profile_data(data["userId"], self.version)
if p is None:
return {}
cards = self.data.card.get_user_cards(data["userId"])
cards = await self.data.card.get_user_cards(data["userId"])
if cards is None or len(cards) == 0:
# This should never happen
self.logger.error(
@ -595,7 +595,7 @@ class OngekiBase:
return {"userId": data["userId"], "userData": user_data}
async def handle_get_user_event_ranking_api_request(self, data: Dict) -> Dict:
user_event_ranking_list = self.data.item.get_ranking_event_ranks(self.version, data["userId"])
user_event_ranking_list = await self.data.item.get_ranking_event_ranks(self.version, data["userId"])
if user_event_ranking_list is None:
return {}
@ -618,7 +618,7 @@ class OngekiBase:
}
async def handle_get_user_login_bonus_api_request(self, data: Dict) -> Dict:
user_login_bonus_list = self.data.item.get_login_bonuses(data["userId"])
user_login_bonus_list = await self.data.item.get_login_bonuses(data["userId"])
if user_login_bonus_list is None:
return {}
@ -636,7 +636,7 @@ class OngekiBase:
}
async def handle_get_user_bp_base_request(self, data: Dict) -> Dict:
p = self.data.profile.get_profile(
p = await self.data.profile.get_profile(
self.game, self.version, user_id=data["userId"]
)
if p is None:
@ -649,7 +649,7 @@ class OngekiBase:
}
async def handle_get_user_recent_rating_api_request(self, data: Dict) -> Dict:
recent_rating = self.data.profile.get_profile_recent_rating(data["userId"])
recent_rating = await self.data.profile.get_profile_recent_rating(data["userId"])
if recent_rating is None:
return {
"userId": data["userId"],
@ -666,7 +666,7 @@ class OngekiBase:
}
async def handle_get_user_activity_api_request(self, data: Dict) -> Dict:
activity = self.data.profile.get_profile_activity(data["userId"], data["kind"])
activity = await self.data.profile.get_profile_activity(data["userId"], data["kind"])
if activity is None:
return {}
@ -693,7 +693,7 @@ class OngekiBase:
}
async def handle_get_user_story_api_request(self, data: Dict) -> Dict:
user_stories = self.data.item.get_stories(data["userId"])
user_stories = await self.data.item.get_stories(data["userId"])
if user_stories is None:
return {}
@ -711,7 +711,7 @@ class OngekiBase:
}
async def handle_get_user_chapter_api_request(self, data: Dict) -> Dict:
user_chapters = self.data.item.get_chapters(data["userId"])
user_chapters = await self.data.item.get_chapters(data["userId"])
if user_chapters is None:
return {}
@ -736,7 +736,7 @@ class OngekiBase:
}
async def handle_get_user_character_api_request(self, data: Dict) -> Dict:
user_characters = self.data.item.get_characters(data["userId"])
user_characters = await self.data.item.get_characters(data["userId"])
if user_characters is None:
return {}
@ -754,7 +754,7 @@ class OngekiBase:
}
async def handle_get_user_card_api_request(self, data: Dict) -> Dict:
user_cards = self.data.item.get_cards(data["userId"])
user_cards = await self.data.item.get_cards(data["userId"])
if user_cards is None:
return {}
@ -773,7 +773,7 @@ class OngekiBase:
async def handle_get_user_deck_by_key_api_request(self, data: Dict) -> Dict:
# Auth key doesn't matter, it just wants all the decks
decks = self.data.item.get_decks(data["userId"])
decks = await self.data.item.get_decks(data["userId"])
if decks is None:
return {}
@ -791,7 +791,7 @@ class OngekiBase:
}
async def handle_get_user_trade_item_api_request(self, data: Dict) -> Dict:
user_trade_items = self.data.item.get_trade_items(data["userId"])
user_trade_items = await self.data.item.get_trade_items(data["userId"])
if user_trade_items is None:
return {}
@ -809,7 +809,7 @@ class OngekiBase:
}
async def handle_get_user_scenario_api_request(self, data: Dict) -> Dict:
user_scenerio = self.data.item.get_scenerios(data["userId"])
user_scenerio = await self.data.item.get_scenerios(data["userId"])
if user_scenerio is None:
return {}
@ -827,7 +827,7 @@ class OngekiBase:
}
async def handle_get_user_ratinglog_api_request(self, data: Dict) -> Dict:
rating_log = self.data.profile.get_profile_rating_log(data["userId"])
rating_log = await self.data.profile.get_profile_rating_log(data["userId"])
if rating_log is None:
return {}
@ -845,7 +845,7 @@ class OngekiBase:
}
async def handle_get_user_mission_point_api_request(self, data: Dict) -> Dict:
user_mission_point_list = self.data.item.get_mission_points(self.version, data["userId"])
user_mission_point_list = await self.data.item.get_mission_points(self.version, data["userId"])
if user_mission_point_list is None:
return {}
@ -865,7 +865,7 @@ class OngekiBase:
}
async def handle_get_user_event_point_api_request(self, data: Dict) -> Dict:
user_event_point_list = self.data.item.get_event_points(data["userId"])
user_event_point_list = await self.data.item.get_event_points(data["userId"])
if user_event_point_list is None:
return {}
@ -887,7 +887,7 @@ class OngekiBase:
}
async def handle_get_user_music_item_api_request(self, data: Dict) -> Dict:
user_music_item_list = self.data.item.get_music_items(data["userId"])
user_music_item_list = await self.data.item.get_music_items(data["userId"])
if user_music_item_list is None:
return {}
@ -905,7 +905,7 @@ class OngekiBase:
}
async def handle_get_user_event_music_api_request(self, data: Dict) -> Dict:
user_evt_music_list = self.data.item.get_event_music(data["userId"])
user_evt_music_list = await self.data.item.get_event_music(data["userId"])
if user_evt_music_list is None:
return {}
@ -923,7 +923,7 @@ class OngekiBase:
}
async def handle_get_user_boss_api_request(self, data: Dict) -> Dict:
p = self.data.item.get_bosses(data["userId"])
p = await self.data.item.get_bosses(data["userId"])
if p is None:
return {}
@ -947,20 +947,20 @@ class OngekiBase:
# The isNew fields are new as of Red and up. We just won't use them for now.
if "userData" in upsert and len(upsert["userData"]) > 0:
self.data.profile.put_profile_data(
await self.data.profile.put_profile_data(
user_id, self.version, upsert["userData"][0]
)
if "userOption" in upsert and len(upsert["userOption"]) > 0:
self.data.profile.put_profile_options(user_id, upsert["userOption"][0])
await self.data.profile.put_profile_options(user_id, upsert["userOption"][0])
if "userPlaylogList" in upsert:
for playlog in upsert["userPlaylogList"]:
self.data.score.put_playlog(user_id, playlog)
await self.data.score.put_playlog(user_id, playlog)
if "userActivityList" in upsert:
for act in upsert["userActivityList"]:
self.data.profile.put_profile_activity(
await self.data.profile.put_profile_activity(
user_id,
act["kind"],
act["id"],
@ -972,101 +972,101 @@ class OngekiBase:
)
if "userRecentRatingList" in upsert:
self.data.profile.put_profile_recent_rating(
await self.data.profile.put_profile_recent_rating(
user_id, upsert["userRecentRatingList"]
)
if "userBpBaseList" in upsert:
self.data.profile.put_profile_bp_list(user_id, upsert["userBpBaseList"])
await self.data.profile.put_profile_bp_list(user_id, upsert["userBpBaseList"])
if "userMusicDetailList" in upsert:
for x in upsert["userMusicDetailList"]:
self.data.score.put_best_score(user_id, x)
await self.data.score.put_best_score(user_id, x)
if "userCharacterList" in upsert:
for x in upsert["userCharacterList"]:
self.data.item.put_character(user_id, x)
await self.data.item.put_character(user_id, x)
if "userCardList" in upsert:
for x in upsert["userCardList"]:
self.data.item.put_card(user_id, x)
await self.data.item.put_card(user_id, x)
if "userDeckList" in upsert:
for x in upsert["userDeckList"]:
self.data.item.put_deck(user_id, x)
await self.data.item.put_deck(user_id, x)
if "userTrainingRoomList" in upsert:
for x in upsert["userTrainingRoomList"]:
self.data.profile.put_training_room(user_id, x)
await self.data.profile.put_training_room(user_id, x)
if "userStoryList" in upsert:
for x in upsert["userStoryList"]:
self.data.item.put_story(user_id, x)
await self.data.item.put_story(user_id, x)
if "userChapterList" in upsert:
for x in upsert["userChapterList"]:
self.data.item.put_chapter(user_id, x)
await self.data.item.put_chapter(user_id, x)
if "userMemoryChapterList" in upsert:
for x in upsert["userMemoryChapterList"]:
self.data.item.put_memorychapter(user_id, x)
await self.data.item.put_memorychapter(user_id, x)
if "userItemList" in upsert:
for x in upsert["userItemList"]:
self.data.item.put_item(user_id, x)
await self.data.item.put_item(user_id, x)
if "userMusicItemList" in upsert:
for x in upsert["userMusicItemList"]:
self.data.item.put_music_item(user_id, x)
await self.data.item.put_music_item(user_id, x)
if "userLoginBonusList" in upsert:
for x in upsert["userLoginBonusList"]:
self.data.item.put_login_bonus(user_id, x)
await self.data.item.put_login_bonus(user_id, x)
if "userEventPointList" in upsert:
for x in upsert["userEventPointList"]:
self.data.item.put_event_point(user_id, self.version, x)
await self.data.item.put_event_point(user_id, self.version, x)
if "userMissionPointList" in upsert:
for x in upsert["userMissionPointList"]:
self.data.item.put_mission_point(user_id, self.version, x)
await self.data.item.put_mission_point(user_id, self.version, x)
if "userRatinglogList" in upsert:
for x in upsert["userRatinglogList"]:
self.data.profile.put_profile_rating_log(
await self.data.profile.put_profile_rating_log(
user_id, x["dataVersion"], x["highestRating"]
)
if "userBossList" in upsert:
for x in upsert["userBossList"]:
self.data.item.put_boss(user_id, x)
await self.data.item.put_boss(user_id, x)
if "userTechCountList" in upsert:
for x in upsert["userTechCountList"]:
self.data.score.put_tech_count(user_id, x)
await self.data.score.put_tech_count(user_id, x)
if "userScenerioList" in upsert:
for x in upsert["userScenerioList"]:
self.data.item.put_scenerio(user_id, x)
await self.data.item.put_scenerio(user_id, x)
if "userTradeItemList" in upsert:
for x in upsert["userTradeItemList"]:
self.data.item.put_trade_item(user_id, x)
await self.data.item.put_trade_item(user_id, x)
if "userEventMusicList" in upsert:
for x in upsert["userEventMusicList"]:
self.data.item.put_event_music(user_id, x)
await self.data.item.put_event_music(user_id, x)
if "userTechEventList" in upsert:
for x in upsert["userTechEventList"]:
self.data.item.put_tech_event(user_id, self.version, x)
await self.data.item.put_tech_event(user_id, self.version, x)
# This should be updated once a day in maintenance window, but for time being we will push the update on each upsert
self.data.item.put_tech_event_ranking(user_id, self.version, x)
await self.data.item.put_tech_event_ranking(user_id, self.version, x)
if "userKopList" in upsert:
for x in upsert["userKopList"]:
self.data.profile.put_kop(user_id, x)
await self.data.profile.put_kop(user_id, x)
return {"returnCode": 1, "apiName": "upsertUserAll"}
@ -1076,7 +1076,7 @@ class OngekiBase:
"""
rival_list = []
user_rivals = self.data.profile.get_rivals(data["userId"])
user_rivals = await self.data.profile.get_rivals(data["userId"])
for rival in user_rivals:
tmp = {}
tmp["rivalUserId"] = rival[0]
@ -1100,7 +1100,7 @@ class OngekiBase:
"""
rivals = []
for rival in data["userRivalList"]:
name = self.data.profile.get_profile_name(
name = await self.data.profile.get_profile_name(
rival["rivalUserId"], self.version
)
if name is None:
@ -1135,8 +1135,8 @@ class OngekiBase:
}
@cached(2)
def util_generate_music_list(self, user_id: int) -> List:
music_detail = self.data.score.get_best_scores(user_id)
async def util_generate_music_list(self, user_id: int) -> List:
music_detail = await self.data.score.get_best_scores(user_id)
song_list = []
for md in music_detail: