fix:数据库修复

This commit is contained in:
雅诺狐
2025-08-17 13:56:15 +08:00
parent 0537dcc1c4
commit a9d5cd8958

View File

@@ -444,7 +444,7 @@ class EmojiManager:
Optional[Tuple[str, str]]: (表情包完整文件路径, 表情包描述)如果没有找到则返回None Optional[Tuple[str, str]]: (表情包完整文件路径, 表情包描述)如果没有找到则返回None
""" """
try: try:
self._ensure_db() self.()
_time_start = time.time() _time_start = time.time()
# 获取所有表情包 (从内存缓存中获取) # 获取所有表情包 (从内存缓存中获取)
@@ -661,7 +661,6 @@ class EmojiManager:
"""获取所有表情包并初始化为MaiEmoji类对象更新 self.emoji_objects""" """获取所有表情包并初始化为MaiEmoji类对象更新 self.emoji_objects"""
try: try:
with get_db_session() as session: with get_db_session() as session:
self._ensure_db()
logger.debug("[数据库] 开始加载所有表情包记录 ...") logger.debug("[数据库] 开始加载所有表情包记录 ...")
emoji_instances = session.execute(select(Emoji)).scalars().all() emoji_instances = session.execute(select(Emoji)).scalars().all()
@@ -692,7 +691,7 @@ class EmojiManager:
""" """
try: try:
with get_db_session() as session: with get_db_session() as session:
self._ensure_db() self.()
if emoji_hash: if emoji_hash:
query = session.execute(select(Emoji).where(Emoji.emoji_hash == emoji_hash)).scalars().all() query = session.execute(select(Emoji).where(Emoji.emoji_hash == emoji_hash)).scalars().all()
@@ -745,7 +744,7 @@ class EmojiManager:
return emoji.description return emoji.description
# 如果内存中没有,从数据库查找 # 如果内存中没有,从数据库查找
self._ensure_db() self.()
try: try:
with get_db_session() as session: with get_db_session() as session:
emoji_record = session.execute(select(Emoji).where(Emoji.emoji_hash == emoji_hash)).scalar_one_or_none() emoji_record = session.execute(select(Emoji).where(Emoji.emoji_hash == emoji_hash)).scalar_one_or_none()
@@ -772,7 +771,7 @@ class EmojiManager:
bool: 是否成功删除 bool: 是否成功删除
""" """
try: try:
self._ensure_db() self.()
# 从emoji_objects中查找表情包对象 # 从emoji_objects中查找表情包对象
emoji = await self.get_emoji_from_manager(emoji_hash) emoji = await self.get_emoji_from_manager(emoji_hash)
@@ -812,7 +811,7 @@ class EmojiManager:
bool: 是否成功替换表情包 bool: 是否成功替换表情包
""" """
try: try:
self._ensure_db() self.()
# 获取所有表情包对象 # 获取所有表情包对象
emoji_objects = self.emoji_objects emoji_objects = self.emoji_objects