EXPERIMENTAL: Try not to build pages when we shouldn't have to.
This commit is contained in:
parent
2f4e2daa61
commit
f7d068536a
|
@ -896,6 +896,9 @@
|
||||||
// Website favicon.
|
// Website favicon.
|
||||||
// $config['url_favicon'] = '/favicon.gif';
|
// $config['url_favicon'] = '/favicon.gif';
|
||||||
|
|
||||||
|
// EXPERIMENTAL: Try not to build pages when we shouldn't have to.
|
||||||
|
$config['try_smarter'] = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ====================
|
* ====================
|
||||||
* Mod settings
|
* Mod settings
|
||||||
|
|
|
@ -306,7 +306,7 @@ function sprintf3($str, $vars, $delim = '%') {
|
||||||
$replaces[$delim . $k . $delim] = $v;
|
$replaces[$delim . $k . $delim] = $v;
|
||||||
}
|
}
|
||||||
return str_replace(array_keys($replaces),
|
return str_replace(array_keys($replaces),
|
||||||
array_values($replaces), $str);
|
array_values($replaces), $str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mb_substr_replace($string, $replacement, $start, $length) {
|
function mb_substr_replace($string, $replacement, $start, $length) {
|
||||||
|
@ -344,6 +344,11 @@ function setupBoard($array) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function openBoard($uri) {
|
function openBoard($uri) {
|
||||||
|
global $config, $build_pages;
|
||||||
|
|
||||||
|
if ($config['try_smarter'])
|
||||||
|
$build_pages = array();
|
||||||
|
|
||||||
$board = getBoardInfo($uri);
|
$board = getBoardInfo($uri);
|
||||||
if ($board) {
|
if ($board) {
|
||||||
setupBoard($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) {
|
function index($page, $mod=false) {
|
||||||
global $board, $config, $debug;
|
global $board, $config, $debug;
|
||||||
|
|
||||||
|
@ -1256,15 +1271,20 @@ function checkMute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildIndex() {
|
function buildIndex() {
|
||||||
global $board, $config;
|
global $board, $config, $build_pages;
|
||||||
|
|
||||||
$pages = getPages();
|
$pages = getPages();
|
||||||
$antibot = create_antibot($board['uri']);
|
$antibot = create_antibot($board['uri']);
|
||||||
|
|
||||||
$page = 1;
|
for ($page = 1; $page <= $config['max_pages']; $page++) {
|
||||||
while ($page <= $config['max_pages'] && $content = index($page)) {
|
|
||||||
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $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();
|
$antibot->reset();
|
||||||
|
|
||||||
$content['pages'] = $pages;
|
$content['pages'] = $pages;
|
||||||
|
@ -1273,8 +1293,6 @@ function buildIndex() {
|
||||||
$content['antibot'] = $antibot;
|
$content['antibot'] = $antibot;
|
||||||
|
|
||||||
file_write($filename, Element('index.html', $content));
|
file_write($filename, Element('index.html', $content));
|
||||||
|
|
||||||
$page++;
|
|
||||||
}
|
}
|
||||||
if ($page < $config['max_pages']) {
|
if ($page < $config['max_pages']) {
|
||||||
for (;$page<=$config['max_pages'];$page++) {
|
for (;$page<=$config['max_pages'];$page++) {
|
||||||
|
@ -1671,7 +1689,7 @@ function strip_combining_chars($str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildThread($id, $return = false, $mod = false) {
|
function buildThread($id, $return = false, $mod = false) {
|
||||||
global $board, $config;
|
global $board, $config, $build_pages;
|
||||||
$id = round($id);
|
$id = round($id);
|
||||||
|
|
||||||
if (event('build-thread', $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'])
|
'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)
|
if ($return)
|
||||||
return $body;
|
return $body;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue