refactor: 优化回复检测逻辑,采用非阻塞方案A
移除发送消息后的固定等待时间,改为立即返回主页继续检测下一条消息。这避免了因等待造成的消息处理延迟,提高了消息处理吞吐量。
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user