Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Smith <mrdoctorwho@helldev.net>2021-06-28 11:45:51 +0300
committerJohn Smith <mrdoctorwho@helldev.net>2021-06-28 11:45:51 +0300
commite62597d79c15cab2ba1d62457b5943e4ad30d542 (patch)
tree332c8062f03fad02daf8df0ea67b6df4d05c14de
parentaf3e74260e4ef963561e34b60f322ac74ddbe70e (diff)
Fix performance issues caused by groupchats presence flood; fix groupchat users limit, now defaults to 30 people
-rw-r--r--README.md2
-rw-r--r--extensions/groupchats.py17
-rw-r--r--gateway.py2
-rw-r--r--modules/mod_groupchat_prs.py24
-rw-r--r--modules/mod_iq_vcard.py2
5 files changed, 28 insertions, 19 deletions
diff --git a/README.md b/README.md
index d48a135..818fc63 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ VK4XMPP Transport
VK4XMPP представляет собой транспорт[¹](https://github.com/mrDoctorWho/vk4xmpp#wtf). Из VK в XMPP [²](https://github.com/mrDoctorWho/vk4xmpp#wtf) и обратно. Написан на языке программирования Python (совместим только со второй версией).
-На текущий момент транспорт не развивается. Осуществляется только поддержка существующего решения.
+**На текущий момент транспорт не развивается. Осуществляется только поддержка существующего решения.**
**<a name="features"></a>Возможности**:
diff --git a/extensions/groupchats.py b/extensions/groupchats.py
index 17ba0a1..8959651 100644
--- a/extensions/groupchats.py
+++ b/extensions/groupchats.py
@@ -283,7 +283,7 @@ class Chat(object):
joinChat(chat, name, TransportID, "Lost in time.") # let's rename ourselves
self.users[TransportID] = {"name": name, "jid": TransportID}
- def update(self, userObject, vkChat):
+ def update(self, userObject):
"""
Updates chat users and sends messages
Uses two user lists to prevent losing of any of them
@@ -291,6 +291,7 @@ class Chat(object):
vkChat = self.getVKChat(userObject, self.id)
all_users = vkChat.get("users", [])
everyone = all_users + self.users.keys()
+ everyone = sorted(everyone)[:CHAT_USERS_LIMIT]
# how would it get in there?
if TransportID in everyone:
everyone.remove(TransportID)
@@ -331,7 +332,6 @@ class Chat(object):
self.setSubject(subject)
self.raw_users = all_users
-
def setSubject(self, subject, date=None):
"""
Changes the chat subject
@@ -366,7 +366,7 @@ class Chat(object):
Handle incoming (VK -> XMPP) messages
"""
if self.created:
- self.update(user, vkChat)
+ self.update(user)
body = escape("", uhtml(vkChat["text"]))
body += parseAttachments(user, vkChat)[1]
body += parseForwardedMessages(user, vkChat)[1]
@@ -410,7 +410,7 @@ class Chat(object):
if not chat:
raise RuntimeError("Unable to get a chat! User: %s, id: %s" % (user, id))
users = chat.get("users", [])
- users = sorted(users)[:CHAT_USERS_LIMIT]
+ chat["users"] = sorted(users)
return chat
@staticmethod
@@ -542,9 +542,10 @@ def cleanTheChatsUp():
chats = runDatabaseQuery("select jid, owner, last_used, user from groupchats")
result = []
for (jid, owner, last_used, user) in chats:
- if (time.time() - last_used) >= utils.TimeMachine(CHAT_LIFETIME_LIMIT):
- result.append((jid, owner, user))
- logger.debug("groupchats: time for %s expired (jid: %s)", jid, user)
+ if jid and owner:
+ if (time.time() - last_used) >= utils.TimeMachine(CHAT_LIFETIME_LIMIT):
+ result.append((jid, owner, user))
+ logger.debug("groupchats: time for %s expired (jid: %s)", jid, user)
if result:
exterminateChats(chats=result)
utils.runThread(cleanTheChatsUp, delay=CHAT_CLEANUP_DELAY)
@@ -561,7 +562,7 @@ def initChatExtension():
logger.warning("not starting chats cleaner because CHAT_LIFETIME_LIMIT is not set")
if not isdef("CHAT_USERS_LIMIT"):
global CHAT_USERS_LIMIT
- CHAT_USERS_LIMIT = 50
+ CHAT_USERS_LIMIT = 30
if isdef("ConferenceServer") and ConferenceServer:
diff --git a/gateway.py b/gateway.py
index fce963e..5c499f7 100644
--- a/gateway.py
+++ b/gateway.py
@@ -535,7 +535,7 @@ class VK(object):
A list of VK Message objects
"""
if uid == 0:
- conversations = self.method("messages.getConversations", {"count": count, "filter": filter_})
+ conversations = self.method("messages.getConversations", {"count": count, "filter": filter_}) or {}
conversations = conversations.get("items")
else:
conversations = [{"conversation": {"peer": {"id": uid}}}]
diff --git a/modules/mod_groupchat_prs.py b/modules/mod_groupchat_prs.py
index 3f0b259..3b457d9 100644
--- a/modules/mod_groupchat_prs.py
+++ b/modules/mod_groupchat_prs.py
@@ -21,11 +21,13 @@ def handleChatErrors(source, prs):
# and rejoin timer on 404, 503
destination = prs.getTo().getStripped()
error = prs.getErrorCode()
- status = prs.getStatusCode()
+ status = int(prs.getStatusCode() or 0)
nick = prs.getFrom().getResource()
jid = prs.getJid()
errorType = prs.getTagAttr("error", "type")
user = Chat.getUserObject(source)
+ pType = prs.getType()
+
if user and source in getattr(user, "chats", {}):
chat = user.chats[source]
if chat.creation_failed:
@@ -46,9 +48,14 @@ def handleChatErrors(source, prs):
chat.owner_nickname = prs.getNick()
runDatabaseQuery("update groupchats where jid=? set nick=?",
(source, chat.owner_nickname), set=True)
- elif error or status:
+ elif error or (status / 100 >= 3):
logger.debug("groupchats: presence error (error #%s, status #%s) "
"from source %s (jid: %s)" % (error, status, source, user.source if user else "unknown"))
+
+ if pType in ("available", None) and destination == TransportID:
+ if prs.getTag("x", namespace=xmpp.NS_MUC_USER):
+ raise xmpp.NodeProcessed()
+
raise xmpp.NodeProcessed()
@@ -82,9 +89,10 @@ def handleChatPresences(source, prs):
# TODO: don't rewrite it every time we get a presence
if jid.split("/")[0] == user.source:
nick = prs.getFrom().getResource()
- chat.owner_nickname = nick
- runDatabaseQuery("update groupchats set nick=? where jid=? ", (nick, source), set=True)
- logger.debug("mod_groupchat_prs: setting user nickname to: %s for chat %s and user: %s", nick, source, user.source)
+ if chat.owner_nickname != nick:
+ chat.owner_nickname = nick
+ runDatabaseQuery("update groupchats set nick=? where jid=? ", (nick, source), set=True)
+ logger.debug("mod_groupchat_prs: setting user nickname to: %s for chat %s and user: %s", nick, source, user.source)
raise xmpp.NodeProcessed()
elif user:
@@ -93,8 +101,7 @@ def handleChatPresences(source, prs):
-@utils.safe
-def presence_handler(cl, prs):
+def presence_handler_groupchat(cl, prs):
"""
xmpppy presence callback
Args:
@@ -109,5 +116,6 @@ def presence_handler(cl, prs):
MOD_TYPE = "presence"
-MOD_HANDLERS = ((presence_handler, "", "", True),)
+
+MOD_HANDLERS = ((presence_handler_groupchat, "", "", True),)
MOD_FEATURES = []
diff --git a/modules/mod_iq_vcard.py b/modules/mod_iq_vcard.py
index 44ed55a..f0f8deb 100644
--- a/modules/mod_iq_vcard.py
+++ b/modules/mod_iq_vcard.py
@@ -144,7 +144,7 @@ def vcard_handler(cl, iq):
destination = jidTo.getStripped()
result = iq.buildReply("result")
- logger.debug("got vcard request to %s (jid: %s)", source, destination)
+ logger.debug("got vcard request to %s (jid: %s)", destination, source)
if destination == TransportID:
template = VCARD_TEMPLATE.copy()
template[KEY_URL] = GITHUB_URL