Improve performance in userinfo

* Implement a nick -> user mapping, preventing a superfluous SSCAN on
the entire dataset for when networks are disconnected
* Use one thread for all channels when a network instance is
disconnected, instead of one thread per channel
* Made returns comprising of only a list into tuples
This commit is contained in:
2019-10-17 20:19:35 +01:00
parent a64765121a
commit f34de8940f
3 changed files with 88 additions and 76 deletions

View File

@@ -21,6 +21,7 @@ import main
from utils.logging.log import *
from utils.logging.debug import *
from utils.logging.send import *
from utils.parsing import parsen
from twisted.internet.ssl import DefaultOpenSSLContextFactory
@@ -54,20 +55,8 @@ class IRCRelay(IRCClient):
self.stage2 = stage2
self.loop = None
def parsen(self, user):
step = user.split("!")
nick = step[0]
if len(step) == 2:
step2 = step[1].split("@")
ident, host = step2
else:
ident = nick
host = nick
return [nick, ident, host]
def privmsg(self, user, channel, msg):
nick, ident, host = self.parsen(user)
nick, ident, host = parsen(user)
for i in main.ZNCErrors:
if i in msg:
error("ZNC issue:", msg)
@@ -134,22 +123,6 @@ class IRCBot(IRCClient):
self.chanlimit = 0
def parsen(self, user):
step = user.split("!")
nick = step[0]
if len(step) == 2:
step2 = step[1].split("@")
if len(step2) == 2:
ident, host = step2
else:
ident = nick
host = nick
else:
ident = nick
host = nick
return [nick, ident, host]
def joinChannels(self, channels):
sleeptime = 0.0
increment = 0.8
@@ -178,7 +151,9 @@ class IRCBot(IRCClient):
if cast[i] == "": # a dictionary that changes length with each iteration
del cast[i]
if "muser" in cast.keys():
cast["nick"], cast["ident"], cast["host"] = self.parsen(cast["muser"])
cast["nick"], cast["ident"], cast["host"] = parsen(cast["muser"])
# additional checks here to see if it's a server -- irc.example.net
# discard if it is
#if not cast["type"] in ["nick", "kick", "quit", "part", "join"]:
# del cast["muser"]
if set(["nick", "ident", "host", "msg"]).issubset(set(cast)):
@@ -507,7 +482,7 @@ class IRCBot(IRCClient):
lc = self._getWho[channel]
lc.stop()
del self._getWho[channel]
userinfo.delChannel(self.net, channel) # < we do not need to deduplicate this
userinfo.delChannels(self.net, [channel]) # < we do not need to deduplicate this
#log("Can no longer cover %s, removing records" % channel)# as it will only be matched once --
# other bots have different nicknames so
def left(self, user, channel, message): # even if they saw it, they wouldn't react
@@ -529,7 +504,7 @@ class IRCBot(IRCClient):
self.event(type="kick", muser=kicker, channel=channel, message=message, user=kickee)
def chanlessEvent(self, cast):
cast["nick"], cast["ident"], cast["host"] = self.parsen(cast["muser"])
cast["nick"], cast["ident"], cast["host"] = parsen(cast["muser"])
if dedup(self.name, cast): # Needs to be kept self.name until the dedup
# function is converted to the new net, num
# format
@@ -590,7 +565,7 @@ class IRCBotFactory(ReconnectingClientFactory):
def clientConnectionLost(self, connector, reason):
if not self.relay:
userinfo.delNetwork(self.net, self.client.channels)
userinfo.delChannels(self.net, self.client.channels)
if not self.client == None:
self.client.connected = False
self.client.channels = []