From 4e3757e5868f9cd1b7ddacb1387414080ad506ae Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Tue, 11 Oct 2011 02:58:22 +1100 Subject: [PATCH] Combined SQL query for checking if locked, etc. Much more efficient. --- post.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/post.php b/post.php index 6c932c3e..83f35b9d 100644 --- a/post.php +++ b/post.php @@ -196,8 +196,17 @@ } //Check if thread exists - if(!$OP && !threadExists($post['thread'])) - error($config['error']['nonexistant']); + if(!$OP) { + $query = prepare(sprintf("SELECT `sticky`,`locked`,`sage` FROM `posts_%s` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); + $query->bindValue(':id', $post['thread'], PDO::PARAM_INT); + $query->execute() or error(db_error()); + + if(!$thread = $query->fetch()) { + // Non-existant + error($config['error']['nonexistant']); + } + } + // Check for an embed field if($config['enable_embedding'] && isset($_POST['embed']) && !empty($_POST['embed'])) { @@ -269,7 +278,7 @@ // Check if thread is locked // but allow mods to post if(!$OP && (!$mod || $mod['type'] < $config['mod']['postinlocked'])) { - if(threadLocked($post['thread'])) + if($thread['locked']) error($config['error']['locked']); } @@ -545,7 +554,7 @@ buildThread(($OP?$id:$post['thread'])); - if(!$OP && strtolower($post['email']) != 'sage' && !threadSageLocked($post['thread']) && ($config['reply_limit'] == 0 || numPosts($post['thread']) < $config['reply_limit'])) { + if(!$OP && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || numPosts($post['thread']) < $config['reply_limit'])) { bumpThread($post['thread']); }