From 9f54f33a915c9f69638cd605aaf310d65e90ab27 Mon Sep 17 00:00:00 2001 From: ruan <2369127-ruany@users.noreply.gitlab.com> Date: Sun, 23 Aug 2020 14:21:34 +0200 Subject: [PATCH] Batch verification into header query when possible --- inc/header.php | 16 +++++++++++----- inc/settings.php | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/inc/header.php b/inc/header.php index 756d64b..2738f37 100644 --- a/inc/header.php +++ b/inc/header.php @@ -13,11 +13,17 @@ function __construct($page) { $t_warnings = $t['warnings']; $t_kicks = $t['kicks']; try { - $st = $page->conn->query("SELECT - (SELECT COUNT(*) FROM $t_bans), - (SELECT COUNT(*) FROM $t_mutes), - (SELECT COUNT(*) FROM $t_warnings), - (SELECT COUNT(*) FROM $t_kicks)"); + $sql = "SELECT + (SELECT id FROM $t_bans ORDER BY id DESC LIMIT 1), + (SELECT id FROM $t_mutes ORDER BY id DESC LIMIT 1), + (SELECT id FROM $t_warnings ORDER BY id DESC LIMIT 1), + (SELECT id FROM $t_kicks ORDER BY id DESC LIMIT 1)"; + + if ($page->settings->verify) { + $sql .= ",(SELECT id FROM " . $t['config'] . " LIMIT 1)"; + } + $st = $page->conn->query($sql); + ($row = $st->fetch(PDO::FETCH_NUM)) or die('Failed to fetch row counts.'); $st->closeCursor(); $this->count = array( diff --git a/inc/settings.php b/inc/settings.php index 5b397df..87c8580 100644 --- a/inc/settings.php +++ b/inc/settings.php @@ -1,5 +1,4 @@ show_silent_bans) { $this->active_query = self::append_query($this->active_query, "silent=" . Settings::$FALSE); } + $this->verify = false; $this->test_strftime(); @@ -176,6 +176,7 @@ class Settings { } protected function connect($verify = true) { + $this->verify = $verify; $driver = $this->driver; $host = $this->host; $port = $this->port; @@ -201,7 +202,7 @@ class Settings { try { $this->conn = new PDO($dsn, $username, $password, $options); - if ($verify) { + if (!$this->header_show_totals && $verify) { $st = $this->conn->query("SELECT * FROM " . $this->table['config'] . " LIMIT 1;"); $st->fetch(); $st->closeCursor();