mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-24 07:30:10 +01:00
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(
|
$config['memcached']['servers'] = Array(
|
||||||
Array('localhost', 11211)
|
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
|
// 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)
|
// The name of the session cookie (PHP's $_SESSION)
|
||||||
$config['cookies']['session']= 'imgboard';
|
$config['cookies']['session']= 'imgboard';
|
||||||
|
@ -588,12 +588,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function index($page, $mod=false) {
|
function index($page, $mod=false) {
|
||||||
global $board, $config;
|
global $board, $config, $memcached;
|
||||||
|
|
||||||
$body = '';
|
$body = '';
|
||||||
$offset = round($page*$config['threads_per_page']-$config['threads_per_page']);
|
$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 = 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(1, $offset, PDO::PARAM_INT);
|
||||||
@ -603,7 +601,14 @@
|
|||||||
if($query->rowcount() < 1 && $page > 1) return false;
|
if($query->rowcount() < 1 && $page > 1) return false;
|
||||||
while($th = $query->fetch()) {
|
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);
|
$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 = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri']));
|
||||||
$posts->bindValue(1, $th['id']);
|
$posts->bindValue(1, $th['id']);
|
||||||
$posts->bindValue(2, ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
$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);
|
$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(
|
return Array(
|
||||||
@ -949,7 +961,6 @@
|
|||||||
function buildIndex() {
|
function buildIndex() {
|
||||||
global $board, $config;
|
global $board, $config;
|
||||||
|
|
||||||
|
|
||||||
$pages = getPages();
|
$pages = getPages();
|
||||||
|
|
||||||
$page = 1;
|
$page = 1;
|
||||||
@ -1224,11 +1235,9 @@
|
|||||||
global $board, $config, $memcached;
|
global $board, $config, $memcached;
|
||||||
$id = round($id);
|
$id = round($id);
|
||||||
|
|
||||||
if($config['memcached']['cache_threads'] && $config['memcached']['enabled'] && $return && $mod) {
|
if($config['memcached']['enabled'] && !$mod) {
|
||||||
// Experimental: cache entire threads (for mods, since we already cache it with static HTML anyway)
|
// Clear cache for index pages
|
||||||
if($body = $memcached->get('thread_' . $board['uri'] . '_' . $id)) {
|
$memcached->delete("theadindex_{$id}");
|
||||||
return $body;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri']));
|
$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'])
|
'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)
|
if($return)
|
||||||
return $body;
|
return $body;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user