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:
+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
|
||||
|
||||
Reference in New Issue
Block a user