Add LIMIT 1 to some of our gets.

git-svn-id: http://svn.automattic.com/wordpress/trunk@3012 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-11-07 23:09:09 +00:00
parent 85723b8944
commit 1a76958310
2 changed files with 5 additions and 5 deletions

View File

@ -557,7 +557,7 @@ function &get_post(&$post, $output = OBJECT) {
if ( isset($post_cache[$post]) ) if ( isset($post_cache[$post]) )
$_post = & $post_cache[$post]; $_post = & $post_cache[$post];
else { else {
$query = "SELECT * FROM $wpdb->posts WHERE ID = '$post'"; $query = "SELECT * FROM $wpdb->posts WHERE ID = '$post' LIMIT 1";
$post_cache[$post] = & $wpdb->get_row($query); $post_cache[$post] = & $wpdb->get_row($query);
$_post = & $post_cache[$post]; $_post = & $post_cache[$post];
} }
@ -596,7 +596,7 @@ function &get_page(&$page, $output = OBJECT) {
} elseif ( $_page = wp_cache_get($page, 'pages') ) { } elseif ( $_page = wp_cache_get($page, 'pages') ) {
// Got it. // Got it.
} else { } else {
$query = "SELECT * FROM $wpdb->posts WHERE ID= '$page'"; $query = "SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1";
$_page = & $wpdb->get_row($query); $_page = & $wpdb->get_row($query);
wp_cache_add($_page->ID, $_page, 'pages'); wp_cache_add($_page->ID, $_page, 'pages');
} }
@ -640,7 +640,7 @@ function &get_category(&$category, $output = OBJECT) {
$_category = $category; $_category = $category;
} else { } else {
if ( ! $_category = wp_cache_get($category, 'category') ) { if ( ! $_category = wp_cache_get($category, 'category') ) {
$_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category'"); $_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category' LIMIT 1");
wp_cache_add($category, $_category, 'category'); wp_cache_add($category, $_category, 'category');
} }
} }
@ -675,7 +675,7 @@ function &get_comment(&$comment, $output = OBJECT) {
$_comment = & $comment_cache[$comment->comment_ID]; $_comment = & $comment_cache[$comment->comment_ID];
} else { } else {
if ( !isset($comment_cache[$comment]) ) { if ( !isset($comment_cache[$comment]) ) {
$_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment'"); $_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment' LIMIT 1");
$comment_cache[$comment->comment_ID] = & $_comment; $comment_cache[$comment->comment_ID] = & $_comment;
} else { } else {
$_comment = & $comment_cache[$comment]; $_comment = & $comment_cache[$comment];

View File

@ -37,7 +37,7 @@ function get_userdata( $user_id ) {
if ( $user ) if ( $user )
return $user; return $user;
if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id'") ) if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id' LIMIT 1") )
return false; return false;
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'"); $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");