Browse Source

Bugfix: Caching complications with thread preview

pull/40/head
Michael Save 12 years ago
parent
commit
6b7daacdb3
  1. 14
      inc/functions.php

14
inc/functions.php

@ -967,19 +967,15 @@ function index($page, $mod=false) {
if ($query->rowcount() < 1 && $page > 1)
return false;
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(
$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['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
);
if (!$mod && $config['cache']['enabled'] && $cached_replies = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
$thread->posts = json_decode($cached_replies);
} else {
$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);
@ -996,6 +992,7 @@ function index($page, $mod=false) {
$po['filename'], $po['ip'], $po['embed'], $mod ? '?/' : $config['root'], $mod)
);
}
}
if ($posts->rowCount() == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
$count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
@ -1009,6 +1006,9 @@ function index($page, $mod=false) {
$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);
$body .= $thread->build(true);

Loading…
Cancel
Save