Browse Source

Fix thread caching

sqlitefix
Trevor Slocum 1 year ago
parent
commit
c4dd643f53
  1. 18
      inc/database/database.php
  2. 2
      inc/database/flatfile.php
  3. 2
      inc/database/mysql.php
  4. 2
      inc/database/mysqli.php
  5. 2
      inc/database/pdo.php
  6. 2
      inc/database/sqlite.php
  7. 2
      inc/database/sqlite3.php
  8. 16
      inc/html.php

18
inc/database/database.php

@ -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];
}

2
inc/database/flatfile.php

@ -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));

2
inc/database/mysql.php

@ -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) {

2
inc/database/mysqli.php

@ -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");

2
inc/database/pdo.php

@ -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)) {

2
inc/database/sqlite.php

@ -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) {

2
inc/database/sqlite3.php

@ -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");

16
inc/html.php

@ -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;

Loading…
Cancel
Save