Browse Source

EXPERIMENTAL: Try not to build pages when we shouldn't have to.

pull/40/head
Michael Foster 11 years ago
parent
commit
f7d068536a
  1. 3
      inc/config.php
  2. 33
      inc/functions.php

3
inc/config.php

@ -896,6 +896,9 @@
// Website favicon.
// $config['url_favicon'] = '/favicon.gif';
// EXPERIMENTAL: Try not to build pages when we shouldn't have to.
$config['try_smarter'] = false;
/*
* ====================
* Mod settings

33
inc/functions.php

@ -344,6 +344,11 @@ function setupBoard($array) {
}
function openBoard($uri) {
global $config, $build_pages;
if ($config['try_smarter'])
$build_pages = array();
$board = getBoardInfo($uri);
if ($board) {
setupBoard($board);
@ -996,6 +1001,16 @@ function clean() {
}
}
function thread_find_page($thread) {
global $config, $board;
$query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC", $board['uri'])) or error(db_error($query));
$threads = $query->fetchAll(PDO::FETCH_COLUMN);
if (($index = array_search($thread, $threads)) === false)
return false;
return floor(($config['threads_per_page'] + $index) / $config['threads_per_page']);
}
function index($page, $mod=false) {
global $board, $config, $debug;
@ -1256,15 +1271,20 @@ function checkMute() {
}
function buildIndex() {
global $board, $config;
global $board, $config, $build_pages;
$pages = getPages();
$antibot = create_antibot($board['uri']);
$page = 1;
while ($page <= $config['max_pages'] && $content = index($page)) {
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) && !in_array($page, $build_pages) && is_file($filename))
continue;
$content = index($page);
if (!$content)
break;
$antibot->reset();
$content['pages'] = $pages;
@ -1273,8 +1293,6 @@ function buildIndex() {
$content['antibot'] = $antibot;
file_write($filename, Element('index.html', $content));
$page++;
}
if ($page < $config['max_pages']) {
for (;$page<=$config['max_pages'];$page++) {
@ -1671,7 +1689,7 @@ function strip_combining_chars($str) {
}
function buildThread($id, $return = false, $mod = false) {
global $board, $config;
global $board, $config, $build_pages;
$id = round($id);
if (event('build-thread', $id))
@ -1719,6 +1737,9 @@ function buildThread($id, $return = false, $mod = false) {
'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index'])
));
if ($config['try_smarter'] && !$mod)
$build_pages[] = thread_find_page($id);
if ($return)
return $body;

Loading…
Cancel
Save