Bugfix: Caching complications with thread preview

This commit is contained in:
Michael Save 2012-09-28 04:46:20 +10:00
parent db14f9ce15
commit 6b7daacdb3

View File

@ -967,34 +967,31 @@ function index($page, $mod=false) {
if ($query->rowcount() < 1 && $page > 1) if ($query->rowcount() < 1 && $page > 1)
return false; return false;
while ($th = $query->fetch()) { while ($th = $query->fetch()) {
if (!$mod && $config['cache']['enabled']) {
if ($built = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
$body .= $built;
continue;
}
}
$thread = new Thread( $thread = new Thread(
$th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'], $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['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'],
$th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod $th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
); );
$posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $board['uri'])); if (!$mod && $config['cache']['enabled'] && $cached_replies = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
$posts->bindValue(':id', $th['id']); $thread->posts = json_decode($cached_replies);
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT); } else {
$posts->execute() or error(db_error($posts)); $posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $board['uri']));
$posts->bindValue(':id', $th['id']);
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
$posts->execute() or error(db_error($posts));
$num_images = 0; $num_images = 0;
while ($po = $posts->fetch()) { while ($po = $posts->fetch()) {
if ($po['file']) if ($po['file'])
$num_images++; $num_images++;
$thread->add(new Post( $thread->add(new Post(
$po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'], $po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'],
$po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'],
$po['filename'], $po['ip'], $po['embed'], $mod ? '?/' : $config['root'], $mod) $po['filename'], $po['ip'], $po['embed'], $mod ? '?/' : $config['root'], $mod)
); );
}
} }
if ($posts->rowCount() == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) { if ($posts->rowCount() == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
@ -1009,14 +1006,17 @@ function index($page, $mod=false) {
$thread->omitted_images = $c['num'] - $num_images; $thread->omitted_images = $c['num'] - $num_images;
} }
if ($config['cache']['enabled'])
cache::set("thread_index_{$board['uri']}_{$th['id']}", json_encode($thread->posts));
$thread->posts = array_reverse($thread->posts); $thread->posts = array_reverse($thread->posts);
$body .= $thread->build(true); $body .= $thread->build(true);
} }
return array( return array(
'board'=>$board, 'board' => $board,
'body'=>$body, 'body' => $body,
'post_url' => $config['post_url'], 'post_url' => $config['post_url'],
'config' => $config, 'config' => $config,
'boardlist' => createBoardlist($mod) 'boardlist' => createBoardlist($mod)