forked from GithubBackups/tinyib
Fix thread caching
This commit is contained in:
parent
8b8c4a88c3
commit
c4dd643f53
@ -21,3 +21,21 @@ if (TINYIB_MODPASS != '') {
|
|||||||
insertAccount($mod);
|
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];
|
||||||
|
}
|
||||||
|
@ -364,7 +364,7 @@ function numRepliesToThreadByID($id) {
|
|||||||
return count($rows);
|
return count($rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
function postsInThreadByID($id, $moderated_only = true) {
|
function _postsInThreadByID($id, $moderated_only = true) {
|
||||||
$compClause = new OrWhereClause();
|
$compClause = new OrWhereClause();
|
||||||
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
|
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
|
||||||
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON));
|
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON));
|
||||||
|
@ -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);
|
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();
|
$posts = array();
|
||||||
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE (`id` = " . $id . " OR `parent` = " . $id . ")" . ($moderated_only ? " AND `moderated` = 1" : "") . " ORDER BY `id` ASC");
|
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE (`id` = " . $id . " OR `parent` = " . $id . ")" . ($moderated_only ? " AND `moderated` = 1" : "") . " ORDER BY `id` ASC");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
@ -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);
|
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;
|
global $link;
|
||||||
$posts = array();
|
$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");
|
$result = mysqli_query($link, "SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE (`id` = " . $id . " OR `parent` = " . $id . ")" . ($moderated_only ? " AND `moderated` = 1" : "") . " ORDER BY `id` ASC");
|
||||||
|
@ -195,7 +195,7 @@ function numRepliesToThreadByID($id) {
|
|||||||
return (int)$result->fetchColumn();
|
return (int)$result->fetchColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
function postsInThreadByID($id, $moderated_only = true) {
|
function _postsInThreadByID($id, $moderated_only = true) {
|
||||||
$posts = array();
|
$posts = array();
|
||||||
$results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = ? OR parent = ?)" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC", array($id, $id));
|
$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)) {
|
while ($row = $results->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
@ -184,7 +184,7 @@ function numRepliesToThreadByID($id) {
|
|||||||
return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = " . $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();
|
$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);
|
$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) {
|
foreach ($result as $post) {
|
||||||
|
@ -215,7 +215,7 @@ function numRepliesToThreadByID($id) {
|
|||||||
return $db->querySingle("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = " . $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;
|
global $db;
|
||||||
$posts = array();
|
$posts = array();
|
||||||
$result = $db->query("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = " . $id . " OR parent = " . $id . ")" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC");
|
$result = $db->query("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = " . $id . " OR parent = " . $id . ")" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC");
|
||||||
|
16
inc/html.php
16
inc/html.php
@ -417,18 +417,11 @@ function backlinks($post) {
|
|||||||
if (!TINYIB_BACKLINKS) {
|
if (!TINYIB_BACKLINKS) {
|
||||||
return '';
|
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'];
|
$needle = '>>' . $post['id'];
|
||||||
|
|
||||||
$return = '';
|
$return = '';
|
||||||
foreach ($thread_cache[$parent_id] as $reply) {
|
foreach ($posts as $reply) {
|
||||||
if (strpos($reply['message'], $needle) !== false) {
|
if (strpos($reply['message'], $needle) !== false) {
|
||||||
if ($return != '') {
|
if ($return != '') {
|
||||||
$return .= ', ';
|
$return .= ', ';
|
||||||
@ -789,9 +782,6 @@ function rebuildIndexes() {
|
|||||||
|
|
||||||
foreach ($threads as $thread) {
|
foreach ($threads as $thread) {
|
||||||
$replies = postsInThreadByID($thread['id']);
|
$replies = postsInThreadByID($thread['id']);
|
||||||
if (!isset($thread_cache[$thread['id']])) {
|
|
||||||
$thread_cache[$thread['id']] = $replies;
|
|
||||||
}
|
|
||||||
$thread['omitted'] = max(0, count($replies) - TINYIB_PREVIEWREPLIES - 1);
|
$thread['omitted'] = max(0, count($replies) - TINYIB_PREVIEWREPLIES - 1);
|
||||||
|
|
||||||
// Build replies for preview
|
// Build replies for preview
|
||||||
@ -831,7 +821,6 @@ function rebuildIndexes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function rebuildThread($id) {
|
function rebuildThread($id) {
|
||||||
global $thread_cache;
|
|
||||||
$id = intval($id);
|
$id = intval($id);
|
||||||
|
|
||||||
$post = postByID($id);
|
$post = postByID($id);
|
||||||
@ -841,7 +830,6 @@ function rebuildThread($id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$posts = postsInThreadByID($id);
|
$posts = postsInThreadByID($id);
|
||||||
$thread_cache[getParent($post)] = $posts;
|
|
||||||
if (count($posts) == 0) {
|
if (count($posts) == 0) {
|
||||||
@unlink('res/' . $id . '.html');
|
@unlink('res/' . $id . '.html');
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user