From bdc15d2869ec96a954d0c42b32feac12a50de678 Mon Sep 17 00:00:00 2001 From: ctrlcctrlv Date: Wed, 28 Aug 2013 21:31:10 +0000 Subject: [PATCH 1/6] Bugfix: Circlepuller is a dumbass and broke many mod actions, don't merge his commits without testing them --- inc/mod/pages.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 105061e9..bba16d6d 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1242,7 +1242,7 @@ function mod_ban_post($board, $delete, $post, $token = false) { // Rebuild board buildIndex(); // Rebuild themes - rebuildThemes('post-delete', $board['uri']); + rebuildThemes('post-delete', $board); } header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); @@ -1338,7 +1338,7 @@ function mod_delete($board, $post) { // Rebuild board buildIndex(); // Rebuild themes - rebuildThemes('post-delete', $board['uri']); + rebuildThemes('post-delete', $board); // Redirect header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } @@ -1360,7 +1360,7 @@ function mod_deletefile($board, $post) { // Rebuild board buildIndex(); // Rebuild themes - rebuildThemes('post-delete', $board['uri']); + rebuildThemes('post-delete', $board); // Redirect header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); @@ -1401,7 +1401,7 @@ function mod_spoiler_image($board, $post) { buildIndex(); // Rebuild themes - rebuildThemes('post-delete', $board['uri']); + rebuildThemes('post-delete', $board); // Redirect header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); From e9a44b4cdae3417ca2ae13798bb7f506c2bb0132 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 29 Aug 2013 08:07:27 +1000 Subject: [PATCH 2/6] Better cache debugging: Show hit/miss, etc. --- inc/cache.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/inc/cache.php b/inc/cache.php index 849748d4..fd89be13 100644 --- a/inc/cache.php +++ b/inc/cache.php @@ -60,10 +60,8 @@ class Cache { break; } - // debug - if ($data !== false && $config['debug']) { - $debug['cached'][] = $key; - } + if ($config['debug']) + $debug['cached'][] = $key . ($data === false ? ' (miss)' : ' (hit)'); return $data; } @@ -95,10 +93,13 @@ class Cache { case 'php': self::$cache[$key] = $value; break; - } + } + + if ($config['debug']) + $debug['cached'][] = $key . ' (set)'; } public static function delete($key) { - global $config; + global $config, $debug; $key = $config['cache']['prefix'] . $key; @@ -119,6 +120,9 @@ class Cache { unset(self::$cache[$key]); break; } + + if ($config['debug']) + $debug['cached'][] = $key . ' (deleted)'; } public static function flush() { global $config; From 2f7a6cdc64e9ca07b1704c4ea83e391e51af6ede Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 29 Aug 2013 08:17:32 +1000 Subject: [PATCH 3/6] wtf? duplicate code --- inc/functions.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index e2289ef1..c0cf47b1 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1776,12 +1776,6 @@ function buildThread($id, $return = false, $mod = false) { $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; file_write($jsonFilename, $json); } - - if ($return) { - return $body; - } else { - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); - } } function rrmdir($dir) { From cadde12090033e5fc16daa23dbd5d1048a3bc9f4 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 29 Aug 2013 08:25:15 +1000 Subject: [PATCH 4/6] Record time started (in milliseconds) at the very beginning of inc/functions.php, even when $config['debug'] is disabled (because we can't tell, yet). Gets a more accurate time for page generation. --- inc/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index c0cf47b1..236e5199 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -9,6 +9,8 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) { exit; } +$microtime_start = microtime(true); + require_once 'inc/display.php'; require_once 'inc/template.php'; require_once 'inc/database.php'; @@ -24,7 +26,7 @@ mb_internal_encoding('UTF-8'); loadConfig(); function loadConfig() { - global $board, $config, $__ip, $debug, $__version; + global $board, $config, $__ip, $debug, $__version, $microtime_start; $error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet'; @@ -82,7 +84,7 @@ function loadConfig() { if ($config['debug']) { if (!isset($debug)) { $debug = array('sql' => array(), 'exec' => array(), 'purge' => array(), 'cached' => array(), 'write' => array()); - $debug['start'] = microtime(true); + $debug['start'] = $microtime_start; } } From 8831f6320096ad82a14fa314fae1e5e9b27ec97a Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 29 Aug 2013 08:30:21 +1000 Subject: [PATCH 5/6] $config['debug']: Show time initializing Tinyboard (before $debug was created) --- inc/functions.php | 1 + inc/template.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/inc/functions.php b/inc/functions.php index 236e5199..ec37a617 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -85,6 +85,7 @@ function loadConfig() { if (!isset($debug)) { $debug = array('sql' => array(), 'exec' => array(), 'purge' => array(), 'cached' => array(), 'write' => array()); $debug['start'] = $microtime_start; + $debug['start_debug'] = microtime(true);; } } diff --git a/inc/template.php b/inc/template.php index ef688944..6f85e78b 100644 --- a/inc/template.php +++ b/inc/template.php @@ -47,7 +47,9 @@ function Element($templateFile, array $options) { if (isset($options['body']) && $config['debug']) { if (isset($debug['start'])) { $debug['time'] = '~' . round((microtime(true) - $debug['start']) * 1000, 2) . 'ms'; + $debug['time (initialization)'] = '~' . round(($debug['start_debug'] - $debug['start']) * 1000, 2) . 'ms'; unset($debug['start']); + unset($debug['start_debug']); } $debug['included'] = get_included_files(); $debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB'; From e2d66724f64f0b7adef381c1d54b7476d84e14b2 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 29 Aug 2013 08:41:36 +1000 Subject: [PATCH 6/6] redundant ORDER BY --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/functions.php b/inc/functions.php index ec37a617..1bd185a9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -647,7 +647,7 @@ function checkBan($board = 0) { if (event('check-ban', $board)) return true; - $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, ``bans``.`id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC, `expires` DESC LIMIT 1"); + $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `seen`, ``bans``.`id` FROM ``bans`` WHERE (`board` IS NULL OR `board` = :board) AND `ip` = :ip ORDER BY `expires` IS NULL DESC, `expires` DESC LIMIT 1"); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':board', $board); $query->execute() or error(db_error($query));