removed buggy memcaching for mods and added a new way of caching to increase index page regeneration times by a lot
This commit is contained in:
parent
8b61b440e7
commit
edd93c5652
@ -53,11 +53,8 @@
|
||||
$config['memcached']['servers'] = Array(
|
||||
Array('localhost', 11211)
|
||||
);
|
||||
// Experimental: cache entire thread HTML (for mods, since we already cache it with static HTML anyway)
|
||||
// Increases load times for mods but might take up a bit of memory
|
||||
$config['memcached']['cache_threads'] = false;
|
||||
// Timeout for cached objects such as posts and HTML
|
||||
$config['memcached']['timeout'] = 86400; // one day
|
||||
$config['memcached']['timeout'] = 43200; // 12 hours
|
||||
|
||||
// The name of the session cookie (PHP's $_SESSION)
|
||||
$config['cookies']['session']= 'imgboard';
|
||||
|
@ -588,13 +588,11 @@
|
||||
}
|
||||
|
||||
function index($page, $mod=false) {
|
||||
global $board, $config;
|
||||
global $board, $config, $memcached;
|
||||
|
||||
$body = '';
|
||||
$offset = round($page*$config['threads_per_page']-$config['threads_per_page']);
|
||||
|
||||
|
||||
|
||||
$query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT ?,?", $board['uri']));
|
||||
$query->bindValue(1, $offset, PDO::PARAM_INT);
|
||||
$query->bindValue(2, $config['threads_per_page'], PDO::PARAM_INT);
|
||||
@ -604,6 +602,13 @@
|
||||
while($th = $query->fetch()) {
|
||||
$thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $th['embed'], $mod ? '?/' : $config['root'], $mod);
|
||||
|
||||
if($config['memcached']['enabled']) {
|
||||
if($built = $memcached->get("theadindex_{$th['id']}")) {
|
||||
$body .= $built;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri']));
|
||||
$posts->bindValue(1, $th['id']);
|
||||
$posts->bindValue(2, ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
||||
@ -630,7 +635,14 @@
|
||||
}
|
||||
|
||||
$thread->posts = array_reverse($thread->posts);
|
||||
$body .= '<div id="thread_' . $thread->id . '">' . $thread->build(true) . '</div>';
|
||||
|
||||
$built = '<div id="thread_' . $thread->id . '">' . $thread->build(true) . '</div>';
|
||||
|
||||
if($config['memcached']['enabled']) {
|
||||
$memcached->set("theadindex_{$th['id']}", $built, time() + $config['memcached']['timeout']);
|
||||
}
|
||||
|
||||
$body .= $built;
|
||||
}
|
||||
|
||||
return Array(
|
||||
@ -949,7 +961,6 @@
|
||||
function buildIndex() {
|
||||
global $board, $config;
|
||||
|
||||
|
||||
$pages = getPages();
|
||||
|
||||
$page = 1;
|
||||
@ -1224,11 +1235,9 @@
|
||||
global $board, $config, $memcached;
|
||||
$id = round($id);
|
||||
|
||||
if($config['memcached']['cache_threads'] && $config['memcached']['enabled'] && $return && $mod) {
|
||||
// Experimental: cache entire threads (for mods, since we already cache it with static HTML anyway)
|
||||
if($body = $memcached->get('thread_' . $board['uri'] . '_' . $id)) {
|
||||
return $body;
|
||||
}
|
||||
if($config['memcached']['enabled'] && !$mod) {
|
||||
// Clear cache for index pages
|
||||
$memcached->delete("theadindex_{$id}");
|
||||
}
|
||||
|
||||
$query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri']));
|
||||
@ -1257,10 +1266,6 @@
|
||||
'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['uri'] . '/' . $config['file_index'])
|
||||
));
|
||||
|
||||
if($config['memcached']['cache_threads'] && $config['memcached']['enabled'] && $mod) {
|
||||
$memcached->set('thread_' . $board['uri'] . '_' . $id, $body, time() + $config['memcached']['timeout']);
|
||||
}
|
||||
|
||||
if($return)
|
||||
return $body;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user