优化@批处理窗口:每10分钟仅处理10-20分钟前消息
- 调整待抽取@查询逻辑:默认仅扫描 timestamp 在 [NOW-20m, NOW-10m) 的消息 - 保留 mentioned_user_ids 为空才处理的条件,处理过自动跳过 - 更新 MessageStorage 与系统任务调用参数,统一使用窗口化批处理配置 - 增加窗口参数兜底修正,避免错误配置导致全量扫描
This commit is contained in:
@@ -358,18 +358,25 @@ class MessageStorage:
|
||||
except Exception as e:
|
||||
logger.exception(f"定时处理媒体任务出错: {e}")
|
||||
|
||||
async def process_pending_mentions(self, batch_size: int = 200, max_age_days: int = 7):
|
||||
async def process_pending_mentions(
|
||||
self,
|
||||
batch_size: int = 200,
|
||||
window_start_minutes: int = 20,
|
||||
window_end_minutes: int = 10,
|
||||
):
|
||||
"""定时任务:批量处理待抽取 @ 的消息并写入社交图。
|
||||
|
||||
说明:
|
||||
1. 该任务与主消息归档链路解耦,不阻塞实时收发;
|
||||
2. 每次只处理有限批次,避免长事务和数据库抖动;
|
||||
3. 重复执行安全:底层按 message_id + sender + mentioned_user_id 做幂等控制。
|
||||
4. 默认只处理 10~20 分钟前的数据,减少对热数据区间的扫描压力。
|
||||
"""
|
||||
try:
|
||||
stats = self.message_db.process_pending_mentions(
|
||||
batch_size=batch_size,
|
||||
max_age_days=max_age_days,
|
||||
window_start_minutes=window_start_minutes,
|
||||
window_end_minutes=window_end_minutes,
|
||||
)
|
||||
total = int(stats.get("total", 0))
|
||||
if total == 0:
|
||||
|
||||
Reference in New Issue
Block a user