From 420075d96712c648c8f42f1f01cbad8056d1ec7d Mon Sep 17 00:00:00 2001 From: Ruan Date: Fri, 3 Jul 2015 18:09:29 +0200 Subject: [PATCH] Use simple queries instead of inner join, might improve performance --- bans.php | 2 +- includes/page.php | 34 ++++++++++++++++++++-------------- mutes.php | 2 +- warnings.php | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bans.php b/bans.php index f61883b..8dbcaa2 100644 --- a/bans.php +++ b/bans.php @@ -64,7 +64,7 @@ $expiresResult = millis_to_date($row['until']); ?> - + diff --git a/includes/page.php b/includes/page.php index 6b31bcc..49a8c21 100644 --- a/includes/page.php +++ b/includes/page.php @@ -5,10 +5,9 @@ require_once './includes/settings.php'; litebans_connect(); - function get_query($table) { - global $table_history, $active_query, $limit_per_page; - return 'SELECT * FROM ' . $table . ' INNER JOIN ' . $table_history . ' on ' . $table . '.uuid=' . $table_history . '.uuid ' . $active_query . + global $active_query, $limit_per_page; + return 'SELECT * FROM ' . $table . $active_query . ' GROUP BY ' . $table . '.id ORDER BY time DESC LIMIT ' . $limit_per_page; } @@ -26,21 +25,28 @@ function get_avatar($name) { return "" . $name; } -$banner_name_cache = []; +$uuid_name_cache = []; -function get_banner_name($row) { - global $conn, $table_history, $banner_name_cache; - $uuid = $row['banned_by_uuid']; - if (array_key_exists($uuid, $banner_name_cache)) return $banner_name_cache[$uuid]; +function get_name($uuid) { + global $conn, $table_history, $uuid_name_cache; + if (array_key_exists($uuid, $uuid_name_cache)) return $uuid_name_cache[$uuid]; $stmt = $conn->prepare("SELECT name FROM " . $table_history . " WHERE uuid=? ORDER BY date DESC LIMIT 1"); - if ($stmt->execute(array($uuid)) && $r = $stmt->fetch()) { - $banner = $r['name']; - $banner_name_cache[$uuid] = $banner; + if ($stmt->execute(array($uuid)) && $row = $stmt->fetch()) { + $banner = $row['name']; + $uuid_name_cache[$uuid] = $banner; return $banner; } - //return "null"; - $banner = $row['banned_by_name']; - return clean($banner); + return null; +} + +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) { diff --git a/mutes.php b/mutes.php index 9e0461e..35c9c90 100644 --- a/mutes.php +++ b/mutes.php @@ -31,7 +31,7 @@ $expiresResult = millis_to_date($row['until']); ?> - + diff --git a/warnings.php b/warnings.php index c609a6c..3f93d56 100644 --- a/warnings.php +++ b/warnings.php @@ -40,7 +40,7 @@ $expiresResult = millis_to_date($row['until']); ?> - +