Fix searching in only bans, or only mutes.
We can't use LIMIT and OFFSET if we are going to filter mutes/bans later. We have to get *all* bans and mutes, filter, and do the pagination manually.
This commit is contained in:
parent
9c4c948a7f
commit
c59d11c308
|
@ -335,10 +335,10 @@ def getBans(id=None, mask=None, kicks=True, oldbans=True, bans=True, floodbots=T
|
||||||
if not floodbots:
|
if not floodbots:
|
||||||
where.append("operator NOT LIKE 'floodbot%%'")
|
where.append("operator NOT LIKE 'floodbot%%'")
|
||||||
if operator:
|
if operator:
|
||||||
where.append("operator LIKE %s") ## LIKE or ==? --tsimpson
|
where.append("operator LIKE %s")
|
||||||
args.append(operator)
|
args.append(operator)
|
||||||
if channel:
|
if channel:
|
||||||
where.append("channel LIKE %s") ## LIKE or ==? --tsimpson
|
where.append("channel LIKE %s")
|
||||||
args.append(channel)
|
args.append(channel)
|
||||||
if not kicks:
|
if not kicks:
|
||||||
where.append("mask LIKE '%%!%%'")
|
where.append("mask LIKE '%%!%%'")
|
||||||
|
@ -362,7 +362,6 @@ def getBans(id=None, mask=None, kicks=True, oldbans=True, bans=True, floodbots=T
|
||||||
if limit:
|
if limit:
|
||||||
sql += " LIMIT %s OFFSET %s" % (limit, offset)
|
sql += " LIMIT %s OFFSET %s" % (limit, offset)
|
||||||
#print sql, "<br/>"
|
#print sql, "<br/>"
|
||||||
#print sql_count, "<br/>"
|
|
||||||
#print args, "<br/>"
|
#print args, "<br/>"
|
||||||
# Things seems faster if we do the query BEFORE counting. Due to caches probably.
|
# Things seems faster if we do the query BEFORE counting. Due to caches probably.
|
||||||
bans = db_execute(sql, args).fetchall()
|
bans = db_execute(sql, args).fetchall()
|
||||||
|
@ -407,22 +406,40 @@ if not bans:
|
||||||
chan = form['channel'].value
|
chan = form['channel'].value
|
||||||
if 'operator' in form:
|
if 'operator' in form:
|
||||||
oper = form['operator'].value
|
oper = form['operator'].value
|
||||||
|
|
||||||
|
filter_mutes = not (isOn('mutes') or isOn('oldmutes'))
|
||||||
|
filter_bans = not (isOn('bans') or isOn('oldbans'))
|
||||||
|
filter_bans_or_mutes = bool(filter_bans) ^ bool(filter_mutes)
|
||||||
|
if filter_bans_or_mutes:
|
||||||
|
# we are going to filter the mutes from ban list, this sucks, because then we can't
|
||||||
|
# paginate correctly using SQL with LIMIT and OFFSET, so we *have* to get all bans and
|
||||||
|
# paginate manually.
|
||||||
|
limit = offset = None
|
||||||
|
else:
|
||||||
|
limit = num_per_page
|
||||||
|
offset = num_per_page * page
|
||||||
bans, ban_count = getBans(mask=query, kicks=isOn('kicks'),
|
bans, ban_count = getBans(mask=query, kicks=isOn('kicks'),
|
||||||
oldbans=isOn('oldbans') or isOn('oldmutes'),
|
oldbans=isOn('oldbans') or isOn('oldmutes'),
|
||||||
bans=isOn('bans') or isOn('mutes'),
|
bans=isOn('bans') or isOn('mutes'),
|
||||||
floodbots=isOn('floodbots'),
|
floodbots=isOn('floodbots'),
|
||||||
operator=oper,
|
operator=oper,
|
||||||
channel=chan,
|
channel=chan,
|
||||||
limit=num_per_page,
|
limit=limit,
|
||||||
offset=num_per_page * page,
|
offset=offset,
|
||||||
withCount=True)
|
withCount=True)
|
||||||
|
|
||||||
if not (isOn('mutes') or isOn('oldmutes')):
|
#print 'filtering', filter_bans_or_mutes, '<br/>'
|
||||||
bans = filter(lambda x: filterMutes(x), bans)
|
#print "total count", ban_count, "bans", len(bans), '<br/>'
|
||||||
ban_count = len(bans)
|
if filter_bans_or_mutes:
|
||||||
elif not (isOn('bans') or isOn('oldbans')):
|
if filter_mutes:
|
||||||
bans = filter(lambda x: not filterMutes(x), bans)
|
bans = filter(lambda x: filterMutes(x), bans)
|
||||||
|
elif filter_bans:
|
||||||
|
bans = filter(lambda x: not filterMutes(x), bans)
|
||||||
ban_count = len(bans)
|
ban_count = len(bans)
|
||||||
|
# pick the bans for current page, since we didn't do it with SQL
|
||||||
|
if ban_count > num_per_page:
|
||||||
|
bans = bans[page * num_per_page: (page + 1) * num_per_page]
|
||||||
|
#print "total count after filtering", ban_count, '<br/>'
|
||||||
|
|
||||||
# Sort the bans
|
# Sort the bans
|
||||||
def _sortf(x1,x2,field):
|
def _sortf(x1,x2,field):
|
||||||
|
|
Loading…
Reference in New Issue