From 23e3d57c5cebbb53bad9b8635c050c2d9aa2ab97 Mon Sep 17 00:00:00 2001 From: Ruan Date: Fri, 3 Jul 2015 17:53:57 +0200 Subject: [PATCH] Reduce wasted queries --- includes/page.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/page.php b/includes/page.php index 45afbb6..6b31bcc 100644 --- a/includes/page.php +++ b/includes/page.php @@ -5,6 +5,7 @@ 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 . @@ -25,12 +26,16 @@ function get_avatar($name) { return "" . $name; } +$banner_name_cache = []; + function get_banner_name($row) { - global $conn, $table_history; + 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]; $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; return $banner; } //return "null";