将@抽取与社交图写入改为定时批处理
- 精简 archive_message 主链路:仅做消息归档,不再同步执行@解析与社交统计 - 新增 MessageStorageDB.process_pending_mentions 批处理能力,按批次回填 mentioned_user_ids 并写入社交图 - 新增系统任务 process_pending_mentions,每10分钟执行一次(every_seconds=600) - 增加幂等保护:基于 t_message_mentions 已有记录过滤新增@关系,避免重复累加社交边和热度 - 保留详细中文注释,说明性能优化目标与批处理策略
This commit is contained in:
@@ -43,6 +43,14 @@ def get_system_job_definitions(robot) -> List[Dict[str, Any]]:
|
||||
"trigger_config": {"seconds": 300},
|
||||
"handler": _build_process_pending_images_handler(robot),
|
||||
},
|
||||
{
|
||||
"job_key": "process_pending_mentions",
|
||||
"name": "待抽取@关系处理",
|
||||
"description": "每 10 分钟处理一次待抽取@消息并更新社交图",
|
||||
"trigger_type": "every_seconds",
|
||||
"trigger_config": {"seconds": 600},
|
||||
"handler": _build_process_pending_mentions_handler(robot),
|
||||
},
|
||||
]
|
||||
|
||||
def _build_process_pending_images_handler(robot) -> Callable[[], Awaitable[None]]:
|
||||
@@ -53,6 +61,14 @@ def _build_process_pending_images_handler(robot) -> Callable[[], Awaitable[None]
|
||||
return _handler
|
||||
|
||||
|
||||
def _build_process_pending_mentions_handler(robot) -> Callable[[], Awaitable[None]]:
|
||||
async def _handler():
|
||||
if hasattr(robot, "message_storage") and robot.message_storage:
|
||||
await robot.message_storage.process_pending_mentions(batch_size=200, max_age_days=7)
|
||||
|
||||
return _handler
|
||||
|
||||
|
||||
class SystemJobLoader:
|
||||
"""系统任务加载器:从数据库读取调度配置并注册到 async_job。"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user