SQL cleanup

This commit is contained in:
Michael Foster 2013-07-31 20:51:43 -04:00
parent 6bbe407e18
commit 328484bee7
7 changed files with 64 additions and 69 deletions

View file

@ -39,7 +39,7 @@
$query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM `posts_%s` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM `posts_%s` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
while ($post = $query->fetch()) {
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id']));
$post['board_name'] = $board['name'];
$post['file'] = $config['uri_thumb'] . $post['thumb'];

View file

@ -47,7 +47,7 @@
$query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_images'], $query);
$query = query($query) or error(db_error());
while ($post = $query->fetch()) {
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
openBoard($post['board']);
// board settings won't be available in the template file, so generate links now
@ -67,7 +67,7 @@
$query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_posts'], $query);
$query = query($query) or error(db_error());
while ($post = $query->fetch()) {
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
openBoard($post['board']);
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id'];
@ -78,7 +78,7 @@
}
// Total posts
$query = 'SELECT SUM(`top`) AS `count` FROM (';
$query = 'SELECT SUM(`top`) FROM (';
foreach ($boards as &$_board) {
if (in_array($_board['uri'], $this->excluded))
continue;
@ -86,11 +86,10 @@
}
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
$query = query($query) or error(db_error());
$res = $query->fetch();
$stats['total_posts'] = number_format($res['count']);
$stats['total_posts'] = number_format($query->fetchColumn());
// Unique IPs
$query = 'SELECT COUNT(DISTINCT(`ip`)) AS `count` FROM (';
$query = 'SELECT COUNT(DISTINCT(`ip`)) FROM (';
foreach ($boards as &$_board) {
if (in_array($_board['uri'], $this->excluded))
continue;
@ -98,11 +97,10 @@
}
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
$query = query($query) or error(db_error());
$res = $query->fetch();
$stats['unique_posters'] = number_format($res['count']);
$stats['unique_posters'] = number_format($query->fetchColumn());
// Active content
$query = 'SELECT SUM(`filesize`) AS `count` FROM (';
$query = 'SELECT SUM(`filesize`) FROM (';
foreach ($boards as &$_board) {
if (in_array($_board['uri'], $this->excluded))
continue;
@ -110,8 +108,7 @@
}
$query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
$query = query($query) or error(db_error());
$res = $query->fetch();
$stats['active_content'] = $res['count'];
$stats['active_content'] = $query->fetchColumn();
return Element('themes/recent/recent.html', Array(
'settings' => $settings,

View file

@ -61,9 +61,8 @@
// debug just the graphing (not updating) with the --debug switch
if (!isset($argv[1]) || $argv[1] != '--debug') {
// Update graph
$query = query(sprintf("SELECT MAX(`id`) AS `count` FROM `posts_%s`", $board));
$count = $query->fetch();
$count = $count['count'];
$query = query(sprintf("SELECT MAX(`id`) FROM `posts_%s`", $board));
$count = $query->fetchColumn();
if (!rrd_update($file, Array(
'-t',