From d9a92f58650282fb0188e8619d9e648588048ab8 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Sat, 1 Jul 2023 02:04:30 -0400 Subject: [PATCH] mai2: 4th round of fixes --- titles/mai2/base.py | 7 +++---- titles/mai2/schema/item.py | 13 +++++++++++++ titles/mai2/schema/profile.py | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/titles/mai2/base.py b/titles/mai2/base.py index 5811735..8fa3d79 100644 --- a/titles/mai2/base.py +++ b/titles/mai2/base.py @@ -261,11 +261,9 @@ class Mai2Base: if "userCharacterList" in upsert and len(upsert["userCharacterList"]) > 0: for char in upsert["userCharacterList"]: - self.data.item.put_character( + self.data.item.put_character_( user_id, - char["characterId"], - char["level"], - char["point"], + char ) if "userItemList" in upsert and len(upsert["userItemList"]) > 0: @@ -275,6 +273,7 @@ class Mai2Base: int(item["itemKind"]), item["itemId"], item["stock"], + True ) if "userLoginBonusList" in upsert and len(upsert["userLoginBonusList"]) > 0: diff --git a/titles/mai2/schema/item.py b/titles/mai2/schema/item.py index 4e20383..284365f 100644 --- a/titles/mai2/schema/item.py +++ b/titles/mai2/schema/item.py @@ -333,6 +333,19 @@ class Mai2ItemData(BaseData): if result is None: return None return result.fetchone() + + def put_character_(self, user_id: int, char_data: Dict) -> Optional[int]: + char_data["user"] = user_id + sql = insert(character).values(**char_data) + + conflict = sql.on_duplicate_key_update(**char_data) + result = self.execute(conflict) + if result is None: + self.logger.warn( + f"put_character_: failed to insert item! user_id: {user_id}" + ) + return None + return result.lastrowid def put_character( self, diff --git a/titles/mai2/schema/profile.py b/titles/mai2/schema/profile.py index 9fd11a3..462e238 100644 --- a/titles/mai2/schema/profile.py +++ b/titles/mai2/schema/profile.py @@ -456,7 +456,7 @@ recent_rating = Table( metadata, Column("id", Integer, primary_key=True, nullable=False), Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False), - Column("userRecentRatingList", Integer), + Column("userRecentRatingList", JSON), UniqueConstraint("user", name="mai2_profile_recent_rating_uk"), mysql_charset="utf8mb4", )