Fix thread caching

This commit is contained in:
Trevor Slocum 2021-06-03 17:57:10 -07:00
parent 8b8c4a88c3
commit c4dd643f53
8 changed files with 26 additions and 20 deletions

View File

@ -21,3 +21,21 @@ if (TINYIB_MODPASS != '') {
insertAccount($mod);
}
}
$cache_all = array();
$cache_moderated = array();
function postsInThreadByID($id, $moderated_only = true) {
global $cache_all, $cache_moderated;
if ($moderated_only) {
$cache = &$cache_moderated;
} else {
$cache = &$cache_all;
}
$id = intval($id);
if (!isset($cache[$id])) {
$cache[$id] = _postsInThreadByID($id, $moderated_only);
}
return $cache[$id];
}

View File

@ -364,7 +364,7 @@ function numRepliesToThreadByID($id) {
return count($rows);
}
function postsInThreadByID($id, $moderated_only = true) {
function _postsInThreadByID($id, $moderated_only = true) {
$compClause = new OrWhereClause();
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON));

View File

@ -208,7 +208,7 @@ function numRepliesToThreadByID($id) {
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = " . $id . " AND `moderated` = 1"), 0, 0);
}
function postsInThreadByID($id, $moderated_only = true) {
function _postsInThreadByID($id, $moderated_only = true) {
$posts = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE (`id` = " . $id . " OR `parent` = " . $id . ")" . ($moderated_only ? " AND `moderated` = 1" : "") . " ORDER BY `id` ASC");
if ($result) {

View File

@ -241,7 +241,7 @@ function numRepliesToThreadByID($id) {
return mysqli_result(mysqli_query($link, "SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = " . $id . " AND `moderated` = 1"), 0, 0);
}
function postsInThreadByID($id, $moderated_only = true) {
function _postsInThreadByID($id, $moderated_only = true) {
global $link;
$posts = array();
$result = mysqli_query($link, "SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE (`id` = " . $id . " OR `parent` = " . $id . ")" . ($moderated_only ? " AND `moderated` = 1" : "") . " ORDER BY `id` ASC");

View File

@ -195,7 +195,7 @@ function numRepliesToThreadByID($id) {
return (int)$result->fetchColumn();
}
function postsInThreadByID($id, $moderated_only = true) {
function _postsInThreadByID($id, $moderated_only = true) {
$posts = array();
$results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = ? OR parent = ?)" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC", array($id, $id));
while ($row = $results->fetch(PDO::FETCH_ASSOC)) {

View File

@ -184,7 +184,7 @@ function numRepliesToThreadByID($id) {
return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = " . $id));
}
function postsInThreadByID($id, $moderated_only = true) {
function _postsInThreadByID($id, $moderated_only = true) {
$posts = array();
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = " . $id . " OR parent = " . $id . ")" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC"), SQLITE_ASSOC);
foreach ($result as $post) {

View File

@ -215,7 +215,7 @@ function numRepliesToThreadByID($id) {
return $db->querySingle("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = " . $id);
}
function postsInThreadByID($id, $moderated_only = true) {
function _postsInThreadByID($id, $moderated_only = true) {
global $db;
$posts = array();
$result = $db->query("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = " . $id . " OR parent = " . $id . ")" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC");

View File

@ -417,18 +417,11 @@ function backlinks($post) {
if (!TINYIB_BACKLINKS) {
return '';
}
global $thread_cache;
$parent_id = getParent($post);
if (!isset($thread_cache[$parent_id])) {
$thread_cache[$parent_id] = postsInThreadByID($parent_id);
}
$posts = postsInThreadByID(getParent($post));
$needle = '>>' . $post['id'];
$return = '';
foreach ($thread_cache[$parent_id] as $reply) {
foreach ($posts as $reply) {
if (strpos($reply['message'], $needle) !== false) {
if ($return != '') {
$return .= ', ';
@ -789,9 +782,6 @@ function rebuildIndexes() {
foreach ($threads as $thread) {
$replies = postsInThreadByID($thread['id']);
if (!isset($thread_cache[$thread['id']])) {
$thread_cache[$thread['id']] = $replies;
}
$thread['omitted'] = max(0, count($replies) - TINYIB_PREVIEWREPLIES - 1);
// Build replies for preview
@ -831,7 +821,6 @@ function rebuildIndexes() {
}
function rebuildThread($id) {
global $thread_cache;
$id = intval($id);
$post = postByID($id);
@ -841,7 +830,6 @@ function rebuildThread($id) {
}
$posts = postsInThreadByID($id);
$thread_cache[getParent($post)] = $posts;
if (count($posts) == 0) {
@unlink('res/' . $id . '.html');
return;