make bantracker page go faster, like, 10 times faster.
This commit is contained in:
parent
2f5ae3eca8
commit
af95f4d3e0
|
@ -14,6 +14,7 @@
|
||||||
###
|
###
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
# This needs to be set to the location of the commoncgi.py file
|
# This needs to be set to the location of the commoncgi.py file
|
||||||
sys.path.append('/var/www/bot')
|
sys.path.append('/var/www/bot')
|
||||||
from commoncgi import *
|
from commoncgi import *
|
||||||
|
@ -22,6 +23,8 @@ from commoncgi import *
|
||||||
db = '/home/bot/data/bans.db'
|
db = '/home/bot/data/bans.db'
|
||||||
num_per_page = 100
|
num_per_page = 100
|
||||||
|
|
||||||
|
t1 = time.time()
|
||||||
|
|
||||||
con = sqlite.connect(db)
|
con = sqlite.connect(db)
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
|
||||||
|
@ -178,11 +181,42 @@ for h in [['Channel',0], ['Nick/Mask',1], ['Operator',2], ['Time',6]]:
|
||||||
print '<th>Log</th></tr>'
|
print '<th>Log</th></tr>'
|
||||||
|
|
||||||
# Select and filter bans
|
# Select and filter bans
|
||||||
def getBans(id=None):
|
def getBans(id=None, mask=None, kicks=True, oldbans=True, bans=True, floods=True, operator=None,
|
||||||
if id is None:
|
channel=None):
|
||||||
cur.execute('SELECT channel,mask,operator,time,removal,removal_op,id FROM bans ORDER BY id DESC')
|
sql = "SELECT channel, mask, operator, time, removal, removal_op, id FROM bans"
|
||||||
|
args = []
|
||||||
|
where = []
|
||||||
|
if id:
|
||||||
|
where.append("id = %s")
|
||||||
|
args.append(id)
|
||||||
|
if mask:
|
||||||
|
where.append("mask LIKE %s")
|
||||||
|
args.append('%' + mask + '%')
|
||||||
|
if not floods:
|
||||||
|
where.append("operator NOT LIKE 'floodbot%%'")
|
||||||
|
if operator:
|
||||||
|
where.append("operator LIKE %s")
|
||||||
|
args.append("%" + operator + "%")
|
||||||
|
if channel:
|
||||||
|
where.append("channel LIKE %s")
|
||||||
|
args.append(channel)
|
||||||
|
if not kicks:
|
||||||
|
where.append("mask LIKE '%%!%%'")
|
||||||
|
if not (oldbans or bans):
|
||||||
|
where.append("mask NOT LIKE '%%!%%'")
|
||||||
else:
|
else:
|
||||||
cur.execute('SELECT channel,mask,operator,time,removal,removal_op,id FROM bans ORDER BY id DESC WHERE id = %d', (id,))
|
if kicks:
|
||||||
|
s = "(mask NOT LIKE '%%%%!%%%%' OR (mask LIKE '%%%%!%%%%' AND %s))"
|
||||||
|
else:
|
||||||
|
s = "%s"
|
||||||
|
if not oldbans:
|
||||||
|
where.append(s % "removal IS NULL")
|
||||||
|
elif not bans:
|
||||||
|
where.append(s % "removal IS NOT NULL")
|
||||||
|
sql += " WHERE " + " AND ".join(where)
|
||||||
|
sql += " ORDER BY id DESC"
|
||||||
|
#print where, args, "<br/>"
|
||||||
|
cur.execute(sql, args)
|
||||||
return cur.fetchall()
|
return cur.fetchall()
|
||||||
|
|
||||||
def myfilter(item, regex, kick, ban, oldban, mute, oldmute, floods, operator, channel):
|
def myfilter(item, regex, kick, ban, oldban, mute, oldmute, floods, operator, channel):
|
||||||
|
@ -219,27 +253,29 @@ def getQueryTerm(query, term):
|
||||||
return (query, None)
|
return (query, None)
|
||||||
|
|
||||||
bans = []
|
bans = []
|
||||||
|
oper = chan = False
|
||||||
|
|
||||||
if form.has_key('query'):
|
if form.has_key('query'):
|
||||||
try:
|
query = form['query'].value
|
||||||
bans = getBans(int(form['query'].value))
|
if query.isdigit():
|
||||||
|
bans = getBans(id=int(query))
|
||||||
start = 0; end = 1
|
start = 0; end = 1
|
||||||
except:
|
else:
|
||||||
bans = getBans()
|
if "chan:" in query:
|
||||||
k = b = ob = m = om = fb = False
|
(query, chan) = getQueryTerm(query, "chan:")
|
||||||
oper = chan = False
|
if "oper:" in query:
|
||||||
if form.has_key('kicks'): k = True
|
(query, oper) = getQueryTerm(query, "oper:")
|
||||||
if form.has_key('oldbans'): ob = True
|
bans = getBans(mask=query, kicks=form.has_key('kicks'),
|
||||||
if form.has_key('bans'): b = True
|
oldbans=form.has_key('oldbans'),
|
||||||
if form.has_key('oldmutes'): om = True
|
bans=form.has_key('bans'),
|
||||||
if form.has_key('mutes'): m = True
|
floods=form.has_key('floods'),
|
||||||
if form.has_key('floods'): fb = True
|
operator=oper,
|
||||||
if "chan:" in form['query'].value:
|
channel=chan)
|
||||||
(form['query'].value, chan) = getQueryTerm(form['query'].value, "chan:")
|
#k = b = ob = m = om = fb = False
|
||||||
if "oper:" in form['query'].value:
|
#if form.has_key('oldmutes'): om = True
|
||||||
(form['query'].value, oper) = getQueryTerm(form['query'].value, "oper:")
|
#if form.has_key('mutes'): m = True
|
||||||
regex = re.compile(re.escape(form['query'].value).replace('\%','.*'), re.DOTALL | re.I)
|
#regex = re.compile(re.escape(form['query'].value).replace('\%','.*'), re.DOTALL | re.I)
|
||||||
bans = filter(lambda x: myfilter(x, regex, k, b, ob, m, om, fb, oper, chan), bans)
|
#bans = filter(lambda x: myfilter(x, regex, k, b, ob, m, om, fb, oper, chan), bans)
|
||||||
start = 0; end = len(bans)
|
start = 0; end = len(bans)
|
||||||
else:
|
else:
|
||||||
page = 0
|
page = 0
|
||||||
|
@ -331,6 +367,12 @@ if not bans and form.has_key('query'):
|
||||||
print "<center><u>No matches for:</u> "%s" by %s</center>" % (form['query'].value, oper)
|
print "<center><u>No matches for:</u> "%s" by %s</center>" % (form['query'].value, oper)
|
||||||
else:
|
else:
|
||||||
print "<center><u>No matches for:</u> "%s"</center>" % form['query'].value
|
print "<center><u>No matches for:</u> "%s"</center>" % form['query'].value
|
||||||
|
elif form.has_key('query'):
|
||||||
|
print "<center>Found %s matches</center>" % end
|
||||||
|
|
||||||
|
t2 = time.time()
|
||||||
|
|
||||||
|
print "Generated in %.4f seconds<br/>" % (t2 - t1)
|
||||||
|
|
||||||
# Aaaaaaaaaaaaaaaaand send!
|
# Aaaaaaaaaaaaaaaaand send!
|
||||||
send_page('bans.tmpl')
|
send_page('bans.tmpl')
|
||||||
|
|
Loading…
Reference in New Issue