重命名表情包和图像模型中的哈希字段,统一为 emoji_hash 和 image_description_hash,以提高代码一致性

This commit is contained in:
墨梓柒
2025-05-16 17:08:30 +08:00
parent 9965997139
commit b698d17a76
3 changed files with 12 additions and 12 deletions

View File

@@ -197,7 +197,7 @@ class MaiEmoji:
# 2. 删除数据库记录
try:
will_delete_emoji = Emoji.get(Emoji.hash == self.hash)
will_delete_emoji = Emoji.get(Emoji.emoji_hash == self.hash)
result = will_delete_emoji.delete_instance() # Returns the number of rows deleted.
except Emoji.DoesNotExist:
logger.warning(f"[删除] 数据库中未找到哈希值为 {self.hash} 的表情包记录。")
@@ -260,7 +260,7 @@ def _to_emoji_objects(data):
try:
emoji = MaiEmoji(full_path=full_path)
emoji.hash = emoji_data.hash
emoji.hash = emoji_data.emoji_hash
if not emoji.hash:
logger.warning(f"[加载错误] 数据库记录缺少 'hash' 字段: {full_path}")
load_errors += 1
@@ -405,7 +405,7 @@ class EmojiManager:
def record_usage(self, emoji_hash: str):
"""记录表情使用次数"""
try:
emoji_update = Emoji.get(Emoji.hash == emoji_hash)
emoji_update = Emoji.get(Emoji.emoji_hash == emoji_hash)
emoji_update.usage_count += 1
emoji_update.last_used_time = time.time() # Update last used time
emoji_update.save() # Persist changes to DB
@@ -475,7 +475,7 @@ class EmojiManager:
selected_emoji, similarity, matched_emotion = random.choice(top_emojis) # 把匹配的 emotion 也拿出来喵~
# 更新使用次数
self.record_usage(selected_emoji.hash)
self.record_usage(selected_emoji.emoji_hash)
_time_end = time.time()
@@ -671,7 +671,7 @@ class EmojiManager:
self._ensure_db()
if emoji_hash:
query = Emoji.select().where(Emoji.hash == emoji_hash)
query = Emoji.select().where(Emoji.emoji_hash == emoji_hash)
else:
logger.warning(
"[查询] 未提供 hash将尝试加载所有表情包建议使用 get_all_emoji_from_db 更新管理器状态。"
@@ -804,7 +804,7 @@ class EmojiManager:
# 删除选定的表情包
logger.info(f"[决策] 删除表情包: {emoji_to_delete.description}")
delete_success = await self.delete_emoji(emoji_to_delete.hash)
delete_success = await self.delete_emoji(emoji_to_delete.emoji_hash)
if delete_success:
# 修复:等待异步注册完成

View File

@@ -61,7 +61,7 @@ class ImageManager:
"""
try:
record = ImageDescriptions.get_or_none(
(ImageDescriptions.hash == image_hash) & (ImageDescriptions.type == description_type)
(ImageDescriptions.image_description_hash == image_hash) & (ImageDescriptions.type == description_type)
)
return record.description if record else None
except Exception as e:
@@ -141,7 +141,7 @@ class ImageManager:
# 保存到数据库 (Images表)
try:
img_obj = Images.get((Images.hash == image_hash) & (Images.type == "emoji"))
img_obj = Images.get((Images.emoji_hash == image_hash) & (Images.type == "emoji"))
img_obj.path = file_path
img_obj.description = description
img_obj.timestamp = current_timestamp
@@ -214,7 +214,7 @@ class ImageManager:
# 保存到数据库 (Images表)
try:
img_obj = Images.get((Images.hash == image_hash) & (Images.type == "image"))
img_obj = Images.get((Images.emoji_hash == image_hash) & (Images.type == "image"))
img_obj.path = file_path
img_obj.description = description
img_obj.timestamp = current_timestamp

View File

@@ -100,7 +100,7 @@ class Emoji(BaseModel):
full_path = TextField(unique=True, index=True) # 文件的完整路径 (包括文件名)
format = TextField() # 图片格式
hash = TextField(index=True) # 表情包的哈希值
emoji_hash = TextField(index=True) # 表情包的哈希值
description = TextField() # 表情包的描述
query_count = IntegerField(default=0) # 查询次数(用于统计表情包被查询描述的次数)
is_registered = BooleanField(default=False) # 是否已注册
@@ -160,7 +160,7 @@ class Images(BaseModel):
用于存储图像信息的模型。
"""
hash = TextField(index=True) # 图像的哈希值
emoji_hash = TextField(index=True) # 图像的哈希值
description = TextField(null=True) # 图像的描述
path = TextField(unique=True) # 图像文件的路径
timestamp = FloatField() # 时间戳
@@ -177,7 +177,7 @@ class ImageDescriptions(BaseModel):
"""
type = TextField() # 类型,例如 "emoji"
hash = TextField(index=True) # 图像的哈希值
image_description_hash = TextField(index=True) # 图像的哈希值
description = TextField() # 图像的描述
timestamp = FloatField() # 时间戳