Reduced & updated dependencies.
By default, messages larger than 2.000 characters (sent via tells) get sent via slaves, if these exist. Fixes #3
This commit is contained in:
@@ -17,3 +17,6 @@ class ChatBlob:
|
||||
obj.msg == self.msg and \
|
||||
obj.page_prefix == self.page_prefix and \
|
||||
obj.page_postfix == self.page_postfix
|
||||
|
||||
def __len__(self):
|
||||
return len(self.title + self.msg + self.page_postfix + self.page_prefix)
|
||||
@@ -243,7 +243,11 @@ class CommandService:
|
||||
response = handler["callback"](CommandRequest(conn, channel, sender, reply),
|
||||
*self.process_matches(matches, handler["params"]))
|
||||
if response is not None:
|
||||
reply(response)
|
||||
if len(response) > 2000 and conn.id == "main" and channel == "msg":
|
||||
self.bot.send_mass_message(sender.char_id, response)
|
||||
else:
|
||||
reply(response)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"error processing command: {message}", e)
|
||||
self.relay_hub_service.send_message("access_denied_logger", sender,
|
||||
|
||||
+47
-51
@@ -7,7 +7,6 @@ import time
|
||||
import mariadb
|
||||
# noinspection PyProtectedMember
|
||||
from mariadb._mariadb import ConnectionPool, OperationalError
|
||||
from mysql.connector.cursor import CursorBase
|
||||
from pkg_resources import parse_version
|
||||
|
||||
from conf.config import BotConfig
|
||||
@@ -75,8 +74,8 @@ class DB:
|
||||
if string.__contains__("UPDATE ") or string.__contains__("INSERT "):
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
raise SqlException( f"SQL Error: '{str(e)}' for '{sql}' "
|
||||
f"[{', '.join(map(lambda x: str(x), params))}]") from e
|
||||
raise SqlException(f"SQL Error: '{str(e)}' for '{sql}' "
|
||||
f"[{', '.join(map(lambda x: str(x), params))}]") from e
|
||||
elapsed = time.time() - start_time
|
||||
result = callback(cur)
|
||||
if elapsed > 5:
|
||||
@@ -217,56 +216,53 @@ class DB:
|
||||
if pre_optimized:
|
||||
self._load_optimized_file(filename)
|
||||
return
|
||||
start = time.time()
|
||||
raise SqlException(f"SQL File not optimized: {filename}")
|
||||
# start = time.time()
|
||||
# Short version... instead of executing 90 000 inserts for the itemDB, just do one,
|
||||
# while providing all values during one query
|
||||
with open(filename, mode="r", encoding="UTF-8") as f:
|
||||
insert_batches = []
|
||||
inserts = []
|
||||
others = []
|
||||
stat = ""
|
||||
for i in f.readlines():
|
||||
i = i.strip()
|
||||
if i == "" or i == " ":
|
||||
continue
|
||||
if i.startswith("INSERT INTO"):
|
||||
match2 = re.match("(INSERT INTO .+? VALUES) (\(.+?\));", i)
|
||||
if match2:
|
||||
r2 = match2[2].replace("NULL", "None")
|
||||
r2 = r2.replace("null", "None")
|
||||
query = match2[1] + f" ({', ?' * len(eval(r2))})"
|
||||
query = query.replace("(, ", "(")
|
||||
if stat != query:
|
||||
if stat != "" or len(inserts) != 0:
|
||||
insert_batches.append([stat, inserts])
|
||||
inserts = []
|
||||
stat = query
|
||||
inserts.append(eval(r2))
|
||||
else:
|
||||
if i.startswith("--"):
|
||||
continue
|
||||
others.append(i)
|
||||
insert_batches.append([stat, inserts])
|
||||
with self.shared.lock:
|
||||
with self.shared.pool.get_connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur: CursorBase
|
||||
if others:
|
||||
for statement in others:
|
||||
try:
|
||||
cur.execute(statement)
|
||||
except OperationalError:
|
||||
pass
|
||||
for sql, param in insert_batches:
|
||||
if sql == "INSERT INTO trickle (id, group_name, name, amount_agility, " \
|
||||
"amount_intelligence, amount_psychic, amount_stamina, " \
|
||||
"amount_strength, amount_sense) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)":
|
||||
for row in param:
|
||||
cur.execute(sql, row)
|
||||
continue
|
||||
cur.executemany(sql, param)
|
||||
|
||||
print(f"Runtime: {time.time() - start: .2f} for {filename}")
|
||||
# with open(filename, mode="r", encoding="UTF-8") as f:
|
||||
# insert_batches = []
|
||||
# inserts = []
|
||||
# others = []
|
||||
# stat = ""
|
||||
# for i in f.readlines():
|
||||
# i = i.strip()
|
||||
# if i == "" or i == " ":
|
||||
# continue
|
||||
# if i.startswith("INSERT INTO"):
|
||||
# match2 = re.match("(INSERT INTO .+? VALUES) (\(.+?\));", i)
|
||||
# if match2:
|
||||
# r2 = match2[2].replace("NULL", "None")
|
||||
# r2 = r2.replace("null", "None")
|
||||
# query = match2[1] + f" ({', ?' * len(eval(r2))})"
|
||||
# query = query.replace("(, ", "(")
|
||||
# if stat != query:
|
||||
# if stat != "" or len(inserts) != 0:
|
||||
# insert_batches.append([stat, inserts])
|
||||
# inserts = []
|
||||
# stat = query
|
||||
# inserts.append(eval(r2))
|
||||
# else:
|
||||
# if i.startswith("--"):
|
||||
# continue
|
||||
# others.append(i)
|
||||
# insert_batches.append([stat, inserts])
|
||||
# with self.shared.lock:
|
||||
# with self.shared.pool.get_connection() as conn:
|
||||
# with conn.cursor() as cur:
|
||||
# cur: CursorBase
|
||||
# if others:
|
||||
# for statement in others:
|
||||
# cur.execute(statement)
|
||||
# for sql, param in insert_batches:
|
||||
# if sql == "INSERT INTO trickle (id, group_name, name, amount_agility, " \
|
||||
# "amount_intelligence, amount_psychic, amount_stamina, " \
|
||||
# "amount_strength, amount_sense) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)":
|
||||
# for row in param:
|
||||
# cur.execute(sql, row)
|
||||
# continue
|
||||
# cur.executemany(sql, param)
|
||||
# print(f"Runtime: {time.time() - start: .2f} for {filename}")
|
||||
|
||||
def get_type(self) -> str:
|
||||
return self.type
|
||||
|
||||
+2
-2
@@ -41,8 +41,8 @@ class IgnCore:
|
||||
self.dimension = None
|
||||
self.last_timer_event = 0
|
||||
self.start_time = int(time.time())
|
||||
self.major_version = "IGNCore v2.6"
|
||||
self.minor_version = "7"
|
||||
self.major_version = "IGNCore v2.7"
|
||||
self.minor_version = "0"
|
||||
self.incoming_queue = FifoQueue()
|
||||
self.mass_message_queue = None
|
||||
self.conns = DictObject()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import time
|
||||
|
||||
import requests
|
||||
from mysql.connector.cursor import CursorBase
|
||||
from requests import ReadTimeout
|
||||
|
||||
from core.aochat import server_packets
|
||||
@@ -233,7 +232,6 @@ class PorkService:
|
||||
with self.db.pool.get_connection() as conn:
|
||||
with conn.cursor(dictionary=True) as cur:
|
||||
for packet in self.updates:
|
||||
cur: CursorBase
|
||||
cur.execute(
|
||||
"SELECT char_id, name, first_name, last_name, level, breed, gender, faction, profession, "
|
||||
"profession_title, ai_rank, ai_level, org_id, org_name, org_rank_name, org_rank_id, "
|
||||
|
||||
Reference in New Issue
Block a user