From d7fc5adc22c71261dd3f4544a3a5a1816b8d724e Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 29 Aug 2013 12:38:37 +1000 Subject: Performance: Use only one INSERT INTO (with multiple rows) for tracked cites --- post.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'post.php') diff --git a/post.php b/post.php index 21d294cd..7ca9c1a9 100644 --- a/post.php +++ b/post.php @@ -682,15 +682,14 @@ if (isset($_POST['delete'])) { incrementSpamHash($post['antispam_hash']); } - if (isset($post['tracked_cites'])) { + if (isset($post['tracked_cites']) && count($post['tracked_cites'])) { + $insert_rows = array(); foreach ($post['tracked_cites'] as $cite) { - $query = prepare('INSERT INTO ``cites`` VALUES (:board, :post, :target_board, :target)'); - $query->bindValue(':board', $board['uri']); - $query->bindValue(':post', $id, PDO::PARAM_INT); - $query->bindValue(':target_board',$cite[0]); - $query->bindValue(':target', $cite[1], PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + $insert_rows[] = '(' . + $pdo->quote($board['uri']) . ', ' . (int)$id . ', ' . + $pdo->quote($cite[0]) . ', ' . (int)$cite[1] . ')'; } + query('INSERT INTO ``cites`` VALUES ' . implode(', ', $insert_rows)) or error(db_error());; } if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) { -- cgit v1.3 From a8e37543757a6f5e6e841a3745cdb10b2247a269 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 29 Aug 2013 18:55:25 +1000 Subject: Minor $config['try_smarter'] work --- inc/functions.php | 5 ++++- inc/template.php | 4 +++- post.php | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'post.php') diff --git a/inc/functions.php b/inc/functions.php index d006d0ad..8b338063 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1306,7 +1306,7 @@ function buildIndex() { for ($page = 1; $page <= $config['max_pages']; $page++) { $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); - if ($config['try_smarter'] && isset($build_pages) && count($build_pages) + if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages) && !in_array($page, $build_pages) && is_file($filename)) continue; $content = index($page); @@ -1352,6 +1352,9 @@ function buildIndex() { $jsonFilename = $board['dir'] . 'catalog.json'; file_write($jsonFilename, $json); } + + if ($config['try_smarter']) + $build_pages = array(); } function buildJavascript() { diff --git a/inc/template.php b/inc/template.php index 6f85e78b..6d417631 100644 --- a/inc/template.php +++ b/inc/template.php @@ -35,7 +35,7 @@ function load_twig() { } function Element($templateFile, array $options) { - global $config, $debug, $twig; + global $config, $debug, $twig, $build_pages; if (!$twig) load_twig(); @@ -51,6 +51,8 @@ function Element($templateFile, array $options) { unset($debug['start']); unset($debug['start_debug']); } + if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages)) + $debug['build_pages'] = $build_pages; $debug['included'] = get_included_files(); $debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB'; $options['body'] .= diff --git a/post.php b/post.php index 7ca9c1a9..de4bc07d 100644 --- a/post.php +++ b/post.php @@ -682,7 +682,7 @@ if (isset($_POST['delete'])) { incrementSpamHash($post['antispam_hash']); } - if (isset($post['tracked_cites']) && count($post['tracked_cites'])) { + if (isset($post['tracked_cites']) && !empty($post['tracked_cites'])) { $insert_rows = array(); foreach ($post['tracked_cites'] as $cite) { $insert_rows[] = '(' . -- cgit v1.3