No point using JSON as Cache class already supports objects
This commit is contained in:
parent
edb9999a7d
commit
cd81ae8ea5
@ -974,9 +974,7 @@ function index($page, $mod=false) {
|
|||||||
$th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
|
$th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($config['cache']['enabled'] && $replies = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
|
if (!$config['cache']['enabled'] || !$replies = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
|
||||||
$replies = json_decode($replies, true);
|
|
||||||
} else {
|
|
||||||
$posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $board['uri']));
|
$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(':id', $th['id']);
|
||||||
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
||||||
@ -985,9 +983,9 @@ function index($page, $mod=false) {
|
|||||||
$replies = $posts->fetchAll(PDO::FETCH_ASSOC);
|
$replies = $posts->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($config['cache']['enabled'])
|
if ($config['cache']['enabled'])
|
||||||
cache::set("thread_index_{$board['uri']}_{$th['id']}", json_encode($replies));
|
cache::set("thread_index_{$board['uri']}_{$th['id']}", $replies);
|
||||||
}
|
}
|
||||||
|
|
||||||
$num_images = 0;
|
$num_images = 0;
|
||||||
foreach ($replies as $po) {
|
foreach ($replies as $po) {
|
||||||
if ($po['file'])
|
if ($po['file'])
|
||||||
@ -1004,16 +1002,14 @@ function index($page, $mod=false) {
|
|||||||
|
|
||||||
if ($post_count == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
|
if ($post_count == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
|
||||||
// Yeah, using two cache objects for one thread seems a little inefficient. This code is messy and dumb; please clean it up if you can.
|
// Yeah, using two cache objects for one thread seems a little inefficient. This code is messy and dumb; please clean it up if you can.
|
||||||
if ($config['cache']['enabled'] && $count = cache::get("thread_index_{$board['uri']}_{$th['id']}_omitted")) {
|
if (!$config['cache']['enabled'] || !$count = cache::get("thread_index_{$board['uri']}_{$th['id']}_omitted")) {
|
||||||
$count = explode(',', $count);
|
|
||||||
} else {
|
|
||||||
$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']));
|
$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']));
|
||||||
$count->bindValue(':thread', $th['id'], PDO::PARAM_INT);
|
$count->bindValue(':thread', $th['id'], PDO::PARAM_INT);
|
||||||
$count->execute() or error(db_error($count));
|
$count->execute() or error(db_error($count));
|
||||||
$count = $count->fetchAll(PDO::FETCH_COLUMN);
|
$count = $count->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
if ($config['cache']['enabled'])
|
if ($config['cache']['enabled'])
|
||||||
cache::set("thread_index_{$board['uri']}_{$th['id']}_omitted", implode(',', $count));
|
cache::set("thread_index_{$board['uri']}_{$th['id']}_omitted", $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
$thread->omitted = $count[0] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
|
$thread->omitted = $count[0] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
|
||||||
|
Loading…
Reference in New Issue
Block a user