wechaty / puppet-wechat

Wechaty Puppet Provider for WeChat
https://www.npmjs.com/package/wechaty-puppet-wechat
Apache License 2.0
405 stars 67 forks source link

1.x版本消息监听延迟严重,当在群里@人后,会导致消息监听不及时,有很大的延时,已经找到原因 #207

Open leochen-g opened 2 years ago

leochen-g commented 2 years ago

1.x版本的 puppet-wechat新增了一个消息的属性mentionIdList,顾名思义是获取消息中mention的用户id,但是正是因为有这个方法,会导致消息延时严重,我本地测试了一下,在没有@人的情况下时间是 0.577ms,当在群里有一个@的时候时间已经是6.3s,

测试时间截图

image image

主要影响的方法:

测试后发现如果有@人员,会导致循环所有群内成员,如果遇到同名群,会循环查询多次,而这个查询同样是耗时操作,最后导致消息事件延时严重,目前正寻找解决方法,同时希望能得到 @huan 的帮助来一块看一下

image image
huan commented 2 years ago

Thanks for locating this part of the code!

It might have performance issues related to this part of the code. However, this code has been used for many years, and it was not introduced by the v1.x upgrade in the past year.

Just F.Y.I.

gtyhn commented 2 years ago

同样遇到此问题,刚开始我还怀疑是用 ts 写的代码性能有问题,后来发现在群里不使用@能很快收到消息,一旦有@,延迟至少四五秒以上,有没解决办法?不行的话我得先把 mention 功能给屏了尝试自己解析了,要不然这功能没法用