mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
refactor(增量分析): 移除未使用的兼容代码
- 移除 IncrementalStore.migrate_legacy_state (新功能尚未发布,无需迁移) - 移除 entities/__init__.py 中的 AnalysisResult 别名
This commit is contained in:
@@ -21,14 +21,10 @@ from .analysis_result import (
|
||||
from .analysis_task import AnalysisTask, TaskStatus
|
||||
from .incremental_state import IncrementalBatch, IncrementalState
|
||||
|
||||
# 别名,保持向后兼容
|
||||
AnalysisResult = GroupAnalysisResult
|
||||
|
||||
__all__ = [
|
||||
"AnalysisTask",
|
||||
"TaskStatus",
|
||||
"GroupAnalysisResult",
|
||||
"AnalysisResult", # 别名
|
||||
"SummaryTopic",
|
||||
"UserTitle",
|
||||
"GoldenQuote",
|
||||
|
||||
@@ -356,85 +356,3 @@ class IncrementalStore:
|
||||
index.sort(key=lambda x: x.get("timestamp", 0))
|
||||
return index
|
||||
|
||||
# ================================================================
|
||||
# 旧版兼容(迁移期间使用)
|
||||
# ================================================================
|
||||
|
||||
async def migrate_legacy_state(
|
||||
self, group_id: str, date_str: str
|
||||
) -> bool:
|
||||
"""
|
||||
尝试迁移旧版按天存储的 IncrementalState 到新批次架构。
|
||||
|
||||
检查旧键 incremental_state_{group_id}_{date_str} 是否存在,
|
||||
如果存在则将其数据转换为一个 IncrementalBatch 并保存,
|
||||
然后删除旧键。
|
||||
|
||||
Args:
|
||||
group_id: 群组 ID
|
||||
date_str: 日期字符串 (YYYY-MM-DD)
|
||||
|
||||
Returns:
|
||||
bool: 是否成功迁移(True=迁移了数据,False=无需迁移或失败)
|
||||
"""
|
||||
old_key = f"incremental_state_{group_id}_{date_str}"
|
||||
|
||||
try:
|
||||
old_data = await self.plugin.get_kv_data(old_key, None)
|
||||
if old_data is None:
|
||||
return False
|
||||
|
||||
logger.info(
|
||||
f"发现旧版增量状态 (群 {group_id}, 日期 {date_str}),开始迁移"
|
||||
)
|
||||
|
||||
# 从旧数据中提取信息构建一个聚合批次
|
||||
batch = IncrementalBatch(
|
||||
group_id=group_id,
|
||||
timestamp=old_data.get("created_at", time.time()),
|
||||
messages_count=old_data.get("total_message_count", 0),
|
||||
characters_count=old_data.get("total_character_count", 0),
|
||||
hourly_msg_counts=old_data.get("hourly_message_counts", {}),
|
||||
hourly_char_counts=old_data.get("hourly_character_counts", {}),
|
||||
user_stats=old_data.get("user_activities", {}),
|
||||
emoji_stats=old_data.get("emoji_counts", {}),
|
||||
topics=old_data.get("topics", []),
|
||||
golden_quotes=old_data.get("golden_quotes", []),
|
||||
token_usage=old_data.get("total_token_usage", {
|
||||
"prompt_tokens": 0,
|
||||
"completion_tokens": 0,
|
||||
"total_tokens": 0,
|
||||
}),
|
||||
last_message_timestamp=old_data.get(
|
||||
"last_analyzed_message_timestamp", 0
|
||||
),
|
||||
participant_ids=list(
|
||||
old_data.get("all_participant_ids", [])
|
||||
),
|
||||
)
|
||||
|
||||
# 保存为新批次
|
||||
saved = await self.save_batch(batch)
|
||||
if not saved:
|
||||
logger.error(f"旧版数据迁移保存失败 (群 {group_id})")
|
||||
return False
|
||||
|
||||
# 迁移最后分析时间戳
|
||||
last_ts = old_data.get("last_analyzed_message_timestamp", 0)
|
||||
if last_ts > 0:
|
||||
await self.update_last_analyzed_timestamp(group_id, last_ts)
|
||||
|
||||
# 删除旧键
|
||||
await self.plugin.put_kv_data(old_key, None)
|
||||
|
||||
logger.info(
|
||||
f"旧版增量状态迁移完成 (群 {group_id}, 日期 {date_str}), "
|
||||
f"消息数={batch.messages_count}"
|
||||
)
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"旧版增量状态迁移失败 (群 {group_id}): {e}", exc_info=True
|
||||
)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user