refactor: 优化回复检测逻辑,采用非阻塞方案A

移除发送消息后的固定等待时间,改为立即返回主页继续检测下一条消息。这避免了因等待造成的消息处理延迟,提高了消息处理吞吐量。
This commit is contained in:
2026-03-25 18:26:50 +08:00
parent ffb61e062e
commit 06fa098fe0

View File

@@ -364,6 +364,7 @@ object WeworkLoopImpl {
}
}
//推测是否回复并在房间等待指令
// 方案A发送消息后立即返回主页继续检测下一条消息不等待
if (needInfer) {
val lastMessage = messageList.lastOrNull()
if (lastMessage != null && lastMessage.sender == 0) {
@@ -380,27 +381,14 @@ object WeworkLoopImpl {
|| tempContent.isNotBlank()
) {
LogUtils.v("推测需要回复: $tempContent")
WeworkController.waitingForReply = true
val startTime = System.currentTimeMillis()
var currentTime = startTime
while (mainLoopRunning && currentTime - startTime < timeout) {
sleep(Constant.POP_WINDOW_INTERVAL / 5)
currentTime = System.currentTimeMillis()
}
WeworkController.waitingForReply = false
return getChatMessageList(needInfer = false, titleList = titleList)
// 方案A不清空 waitingForReply,直接返回主页
// 这样主循环会继续检测下一条消息
return true
}
}
2 -> {
WeworkController.waitingForReply = true
val startTime = System.currentTimeMillis()
var currentTime = startTime
while (mainLoopRunning && currentTime - startTime < timeout) {
sleep(Constant.POP_WINDOW_INTERVAL / 5)
currentTime = System.currentTimeMillis()
}
WeworkController.waitingForReply = false
return getChatMessageList(needInfer = false, titleList = titleList)
// 方案A不清空 waitingForReply,直接返回主页
return true
}
else -> return true
}