Use faster query to fetch entry counts

This commit is contained in:
ruan 2018-08-26 15:09:49 +02:00
parent ea93ca37bd
commit 95bdf49a6a
No known key found for this signature in database
GPG Key ID: 0D2EC1C52E469C0B
2 changed files with 9 additions and 17 deletions

View File

@ -14,10 +14,10 @@ function __construct($page) {
$t_kicks = $t['kicks']; $t_kicks = $t['kicks'];
try { try {
$st = $page->conn->query("SELECT $st = $page->conn->query("SELECT
(SELECT COUNT(*) FROM $t_bans), (SELECT id FROM $t_bans ORDER BY id DESC LIMIT 1),
(SELECT COUNT(*) FROM $t_mutes), (SELECT id FROM $t_mutes ORDER BY id DESC LIMIT 1),
(SELECT COUNT(*) FROM $t_warnings), (SELECT id FROM $t_warnings ORDER BY id DESC LIMIT 1),
(SELECT COUNT(*) FROM $t_kicks)"); (SELECT id FROM $t_kicks ORDER BY id DESC LIMIT 1)");
($row = $st->fetch(PDO::FETCH_NUM)) or die('Failed to fetch row counts.'); ($row = $st->fetch(PDO::FETCH_NUM)) or die('Failed to fetch row counts.');
$st->closeCursor(); $st->closeCursor();
$this->count = array( $this->count = array(

View File

@ -231,26 +231,24 @@ final class Settings {
redirect("error/outdated-plugin.php"); redirect("error/outdated-plugin.php");
} }
} }
if ($settings->error_reporting === false) { if ($settings->error_reporting) {
die("Database error: $message");
} else {
die("Database error"); die("Database error");
} }
die("Database error: $message");
} }
private function test_strftime() { private function test_strftime() {
// If you modify this function, you may get an "Assertion failed" error. // If you modify this function, you may get an "Assertion failed" error.
date_default_timezone_set("UTC"); // temporarily set UTC timezone for testing purposes date_default_timezone_set("UTC"); // temporarily set UTC timezone for testing purposes
$fail = false;
$test = gmstrftime($this->date_format, 0); $test = gmstrftime($this->date_format, 0);
if ($test == false) { if ($test == false) {
ob_start(); ob_start();
var_dump($test); var_dump($test);
$testdump = ob_get_clean(); $testdump = ob_get_clean();
echo("Error: date_format test failed. gmstrftime(\"" . $this->date_format . "\",0) returned $testdump"); die("Error: date_format test failed. gmstrftime(\"" . $this->date_format . "\",0) returned $testdump");
$fail = true;
} }
$test = gmstrftime("%Y-%m-%d %H:%M", 0); $test = gmstrftime("%Y-%m-%d %H:%M", 0);
@ -258,13 +256,7 @@ final class Settings {
ob_start(); ob_start();
var_dump($test); var_dump($test);
$testdump = ob_get_clean(); $testdump = ob_get_clean();
echo("Assertion failed: gmstrftime(\"%Y-%m-%d %H:%M\",0) != \"1970-01-01 00:00\"<br>"); die("Assertion failed: gmstrftime(\"%Y-%m-%d %H:%M\",0) != \"1970-01-01 00:00\"<br>Actual result: $testdump");
echo("Actual result: $testdump");
$fail = true;
}
if ($fail === true) {
die;
} }
} }
} }