diff options
| author | Michael Foster <savetheinternet@tinyboard.org> | 2013-07-31 17:02:42 -0400 |
|---|---|---|
| committer | Michael Foster <savetheinternet@tinyboard.org> | 2013-07-31 17:02:42 -0400 |
| commit | c2a287cd142b4ba0940c3026af98d4ff949469de (patch) | |
| tree | 8e0fb67849e9359557353bb57c6197981a78d644 /inc | |
| parent | 6cdf6038754f18af4509ecf078f51894f63c5853 (diff) | |
Only run SQL query to count threads if we really need to
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/functions.php | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/inc/functions.php b/inc/functions.php index 1ffa32df..95487529 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -995,7 +995,10 @@ function index($page, $mod=false) { $query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT); $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; while ($th = $query->fetch()) { $thread = new Thread( @@ -1108,10 +1111,13 @@ function getPageButtons($pages, $mod=false) { function getPages($mod=false) { global $board, $config; - // Count threads - $query = query(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); - - $count = current($query->fetch()); + if (isset($board['thread_count'])) { + $count = $board['thread_count']; + } else { + // Count threads + $query = query(sprintf("SELECT COUNT(`id`) FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); + $count = $query->fetchColumn(); + } $count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']); if ($count < 1) $count = 1; |
