Some optimization of the post query. #2604

git-svn-id: http://svn.automattic.com/wordpress/trunk@3678 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-04-02 00:33:10 +00:00
parent cebb0a3a15
commit 6123ea7eb7
5 changed files with 11 additions and 20 deletions

View File

@ -166,7 +166,7 @@ function upgrade_all() {
if ( $wp_current_db_version < 3308 )
upgrade_160();
if ( $wp_current_db_version < 3582 )
if ( $wp_current_db_version < 3672 )
upgrade_210();
$wp_rewrite->flush_rules();

View File

@ -113,11 +113,12 @@ CREATE TABLE $wpdb->posts (
post_parent bigint(20) NOT NULL default '0',
guid varchar(255) NOT NULL default '',
menu_order int(11) NOT NULL default '0',
post_type varchar(100) NOT NULL default 'post',
post_type varchar(20) NOT NULL default 'post',
post_mime_type varchar(100) NOT NULL default '',
comment_count bigint(20) NOT NULL default '0',
PRIMARY KEY (ID),
KEY post_name (post_name)
KEY post_name (post_name),
KEY type_status_date (post_type, post_status, post_date)
);
CREATE TABLE $wpdb->users (
ID bigint(20) unsigned NOT NULL auto_increment,

View File

@ -505,7 +505,6 @@ class WP_Query {
$result = '';
$where = '';
$limits = '';
$distinct = '';
$join = '';
if ( !isset($q['post_type']) )
@ -822,15 +821,6 @@ class WP_Query {
$q['orderby'] = 'post_date '.$q['order'];
}
//$now = gmdate('Y-m-d H:i:59');
//only select past-dated posts, except if a logged in user is viewing a single: then, if they
//can edit the post, we let them through
//if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) {
// $where .= " AND post_date_gmt <= '$now'";
// $distinct = 'DISTINCT';
//}
if ( $this->is_attachment ) {
$where .= ' AND (post_type = "attachment")';
} elseif ($this->is_page) {
@ -842,8 +832,6 @@ class WP_Query {
if ( is_admin() )
$where .= " OR post_status = 'future' OR post_status = 'draft'";
else
$distinct = 'DISTINCT';
if ( is_user_logged_in() )
$where .= " OR post_author = $user_ID AND post_status = 'private'))";
@ -884,11 +872,13 @@ class WP_Query {
// Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks.
$where = apply_filters('posts_where_paged', $where);
$groupby = " $wpdb->posts.ID ";
$groupby = '';
$groupby = apply_filters('posts_groupby', $groupby);
if ( ! empty($groupby) )
$groupby = 'GROUP BY ' . $groupby;
$join = apply_filters('posts_join_paged', $join);
$orderby = apply_filters('posts_orderby', $q['orderby']);
$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";
$request = " SELECT * FROM $wpdb->posts $join WHERE 1=1 $where $groupby ORDER BY $orderby $limits";
$this->request = apply_filters('posts_request', $request);
$this->posts = $wpdb->get_results($this->request);

View File

@ -470,13 +470,13 @@ function _max_num_pages() {
if (isset($max_num_pages)) return $max_num_pages;
if ( 'posts' == get_query_var('what_to_show') ) {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $wp_query->request, $matches);
preg_match('#FROM\s(.*)\sORDER BY#siU', $wp_query->request, $matches);
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
return ceil($numposts / get_option('posts_per_page'));
} else {
$posts = $wp_query->posts;
preg_match('#WHERE\s(.*)\sGROUP BY#siU', $wp_query->request, $matches);
preg_match('#WHERE\s(.*)\sORDER BY#siU', $wp_query->request, $matches);
$where = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]);
$num_days = $wpdb->query("SELECT DISTINCT post_date FROM $wpdb->posts WHERE $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date)");
return ceil($num_days / get_option('posts_per_page'));

View File

@ -3,6 +3,6 @@
// This just holds the version number, in a separate file so we can bump it without cluttering the SVN
$wp_version = '2.1-alpha1';
$wp_db_version = 3582;
$wp_db_version = 3672;
?>