diff --git a/ladder.php b/ladder.php index 0d6f706b90..7d33e07855 100644 --- a/ladder.php +++ b/ladder.php @@ -3,9 +3,10 @@ include 'lib/ntbb-ladder.lib.php'; $formatid = 'OU'; +$prefix = null; -if (@$_REQUEST['format']) $formatid = $_REQUEST['format']; -if (@$_REQUEST['format']) $prefix = $_REQUEST['prefix']; +if ($_REQUEST['format'] ?? null) $formatid = $_REQUEST['format']; +if ($_REQUEST['prefix'] ?? null) $prefix = $_REQUEST['prefix']; if (!ctype_alnum($formatid)) { die('denied'); diff --git a/lib/ntbb-ladder.lib.php b/lib/ntbb-ladder.lib.php index 41f8427ee4..c2092413a3 100644 --- a/lib/ntbb-ladder.lib.php +++ b/lib/ntbb-ladder.lib.php @@ -206,7 +206,7 @@ function getAllRatings(&$user) { return true; } - function getTop($prefix) { + function getTop($prefix = null) { global $ladderdb; $needUpdate = true; $top = array(); @@ -228,15 +228,15 @@ function getTop($prefix) { // The ladder database can't really handle large queries which aren't indexed, so we instead perform // an indexed query for additional rows and filter them down further. This is obviously *not* guaranteed // to return exactly $limit results, but should be 'good enough' in practice. - $overfetch = $limit * 4; + $overfetch = $limit * 2; $res = $ladderdb->query( - "SELECT * (SELECT * FROM `{$ladderdb->prefix}ladder` WHERE `formatid` = ? ORDER BY `elo` DESC LIMIT ?) WHERE `userid` LIKE ? LIMIT ?)", - [$this->formatid, $overfetch, "{$prefix}%", $limit] + "SELECT * FROM (SELECT * FROM `{$ladderdb->prefix}ladder` WHERE `formatid` = ? ORDER BY `elo` DESC LIMIT $overfetch) AS `unusedalias` WHERE `userid` LIKE ? LIMIT $limit", + [$this->formatid, "$prefix%"] ); } else { $res = $ladderdb->query( - "SELECT * FROM `{$ladderdb->prefix}ladder` WHERE `formatid` = ? ORDER BY `elo` DESC LIMIT ?", - [$this->formatid, $limit] + "SELECT * FROM `{$ladderdb->prefix}ladder` WHERE `formatid` = ? ORDER BY `elo` DESC LIMIT $limit", + [$this->formatid] ); }