Use simple queries instead of inner join, might improve performance

This commit is contained in:
Ruan 2015-07-03 18:09:29 +02:00
parent 23e3d57c5c
commit 420075d967
4 changed files with 23 additions and 17 deletions

View File

@ -64,7 +64,7 @@
$expiresResult = millis_to_date($row['until']); $expiresResult = millis_to_date($row['until']);
?> ?>
<tr> <tr>
<td><?php echo get_avatar($row['name']); ?></td> <td><?php echo get_avatar(get_name($row['uuid'])); ?></td>
<td><?php echo get_avatar(get_banner_name($row)); ?></td> <td><?php echo get_avatar(get_banner_name($row)); ?></td>
<td style="width: 30%;"><?php echo clean($row['reason']); ?></td> <td style="width: 30%;"><?php echo clean($row['reason']); ?></td>
<td><?php echo $timeResult; ?></td> <td><?php echo $timeResult; ?></td>

View File

@ -5,10 +5,9 @@ require_once './includes/settings.php';
litebans_connect(); litebans_connect();
function get_query($table) { function get_query($table) {
global $table_history, $active_query, $limit_per_page; global $active_query, $limit_per_page;
return 'SELECT * FROM ' . $table . ' INNER JOIN ' . $table_history . ' on ' . $table . '.uuid=' . $table_history . '.uuid ' . $active_query . return 'SELECT * FROM ' . $table . $active_query .
' GROUP BY ' . $table . '.id ORDER BY time DESC LIMIT ' . $limit_per_page; ' GROUP BY ' . $table . '.id ORDER BY time DESC LIMIT ' . $limit_per_page;
} }
@ -26,21 +25,28 @@ function get_avatar($name) {
return "<img src='https://cravatar.eu/avatar/" . $name . "/25' style='margin-bottom:5px;margin-right:5px;border-radius:2px;' />" . $name; return "<img src='https://cravatar.eu/avatar/" . $name . "/25' style='margin-bottom:5px;margin-right:5px;border-radius:2px;' />" . $name;
} }
$banner_name_cache = []; $uuid_name_cache = [];
function get_banner_name($row) { function get_name($uuid) {
global $conn, $table_history, $banner_name_cache; global $conn, $table_history, $uuid_name_cache;
$uuid = $row['banned_by_uuid']; if (array_key_exists($uuid, $uuid_name_cache)) return $uuid_name_cache[$uuid];
if (array_key_exists($uuid, $banner_name_cache)) return $banner_name_cache[$uuid];
$stmt = $conn->prepare("SELECT name FROM " . $table_history . " WHERE uuid=? ORDER BY date DESC LIMIT 1"); $stmt = $conn->prepare("SELECT name FROM " . $table_history . " WHERE uuid=? ORDER BY date DESC LIMIT 1");
if ($stmt->execute(array($uuid)) && $r = $stmt->fetch()) { if ($stmt->execute(array($uuid)) && $row = $stmt->fetch()) {
$banner = $r['name']; $banner = $row['name'];
$banner_name_cache[$uuid] = $banner; $uuid_name_cache[$uuid] = $banner;
return $banner; return $banner;
} }
//return "null"; return null;
$banner = $row['banned_by_name']; }
return clean($banner);
function get_banner_name($row) {
$uuid = $row['banned_by_uuid'];
$name = get_name($uuid);
if ($name !== null) {
return $name;
}
$name = $row['banned_by_name'];
return clean($name);
} }
function millis_to_date($millis) { function millis_to_date($millis) {

View File

@ -31,7 +31,7 @@
$expiresResult = millis_to_date($row['until']); $expiresResult = millis_to_date($row['until']);
?> ?>
<tr> <tr>
<td><?php echo get_avatar($row['name']); ?></td> <td><?php echo get_avatar(get_name($row['uuid'])); ?></td>
<td><?php echo get_avatar(get_banner_name($row)); ?></td> <td><?php echo get_avatar(get_banner_name($row)); ?></td>
<td style="width: 30%;"><?php echo clean($row['reason']); ?></td> <td style="width: 30%;"><?php echo clean($row['reason']); ?></td>
<td><?php echo $timeResult; ?></td> <td><?php echo $timeResult; ?></td>

View File

@ -40,7 +40,7 @@
$expiresResult = millis_to_date($row['until']); $expiresResult = millis_to_date($row['until']);
?> ?>
<tr> <tr>
<td><?php echo get_avatar($row['name']); ?></td> <td><?php echo get_avatar(get_name($row['uuid'])); ?></td>
<td><?php echo get_avatar(get_banner_name($row)); ?></td> <td><?php echo get_avatar(get_banner_name($row)); ?></td>
<td style="width: 30%;"><?php echo clean($row['reason']); ?></td> <td style="width: 30%;"><?php echo clean($row['reason']); ?></td>
<td> <td>