1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-01 18:47:20 +01:00

Only run SQL query to count threads if we really need to

This commit is contained in:
Michael Foster 2013-07-31 17:02:42 -04:00
parent 44910c34c3
commit 7619d23499

View File

@ -995,7 +995,10 @@ function index($page, $mod=false) {
$query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT); $query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if ($query->rowcount() < 1 && $page > 1) if ($page == 1 && $query->rowCount() <= $config['threads_per_page'])
$board['thread_count'] = $query->rowCount();
if ($query->rowCount() < 1 && $page > 1)
return false; return false;
while ($th = $query->fetch()) { while ($th = $query->fetch()) {
$thread = new Thread( $thread = new Thread(
@ -1108,10 +1111,13 @@ function getPageButtons($pages, $mod=false) {
function getPages($mod=false) { function getPages($mod=false) {
global $board, $config; global $board, $config;
if (isset($board['thread_count'])) {
$count = $board['thread_count'];
} else {
// Count threads // Count threads
$query = query(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); $query = query(sprintf("SELECT COUNT(`id`) FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
$count = $query->fetchColumn();
$count = current($query->fetch()); }
$count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']); $count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']);
if ($count < 1) $count = 1; if ($count < 1) $count = 1;