--- wp-includes/comment.php.orig        2013-04-12 04:39:04.368995993 -0400
+++ wp-includes/comment.php     2013-05-29 15:07:01.060865823 -0400
@@ -851,16 +851,44 @@
        if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
                return get_page_of_comment( $comment->comment_parent, $args );
 
-       $allowedtypes = array(
-               'comment' => '',
-               'pingback' => 'pingback',
-               'trackback' => 'trackback',
-       );
+        switch ( $args['type'] ) {
+                case 'comment':
+                        $comtype = 'comment';
+                        $comtypewhere = " AND comment_type = ''";
+                        break;
+                case 'pingback':
+                        $comtype = 'pingback';
+                        $comtypewhere = " AND comment_type = 'pingback'";
+                        break;
+                case 'trackback':
+                        $comtype = 'trackback';
+                        $comtypewhere = " AND comment_type = 'trackback'";
+                        break;
+                case 'pings':
+                        $comtype = 'pings';
+                        $comtypewhere = " AND ( comment_type = 'pingback' OR comment_type = 'trackback' )";
+                        break;
+                default;
+                        $comtype = 'all';
+                        $comtypewhere = '';
+        }
 
-       $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
 
-       // Count comments older than this one
+        $cachekey = 'post-' . $comment->comment_post_ID;
+        // Check the cache and set it up if it's not set (so we can use replace later on)
+        if ( false === $oldercoms_cache = wp_cache_get( $cachekey, 'comment_pages' ) ) {
+                $oldercoms_cache = array();
+                wp_cache_add( $cachekey, $oldercoms_cache, 'comment_pages' );
+        }
+        $oldercoms_cache = (array) $oldercoms_cache;
+ 
+        // Get comments older than this comment
+        $oldercoms = ( isset( $oldercoms_cache[$comtype] ) && isset( $oldercoms_cache[$comtype][$comment->comment_ID] ) ) ? $oldercoms_cache[$comtype][$comment->comment_ID] : false;
+        if ( false === $oldercoms ) {
        $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
+                $oldercoms_cache[$comtype][$comment->comment_ID] = $oldercoms;
+                wp_cache_replace( $cachekey, $oldercoms_cache, 'comment_pages' );
+        }
 
        // No older comments? Then it's page #1.
        if ( 0 == $oldercoms )
@@ -871,6 +899,22 @@
 }
 
 /**
+ * Clears the cache used by get_page_of_comment(). Is designed to be attached to the
+ * 'clear_page_of_comment_cache' action inside of wp_transition_comment_status();
+ *
+ * @since 2.9.0
+ * @uses wp_cache_delete() Does the cache deleting.
+ *
+ * @param string $new_status Unused
+ * @param string $old_status Unused
+ * @param object $comment Comment object that had it's status changed
+ * @return bool True on successful removal, false on failure
+ */
+function clear_page_of_comment_cache( $new_status, $old_status, $comment ) {
+        return wp_cache_delete( 'post-' . $comment->comment_post_ID, 'comment_pages' );
+}
+
+/**
  * Does comment contain blacklisted characters or words.
  *
  * @since 1.5.0
--- wp-includes/default-filters.php.save        2013-05-29 14:57:45.309225385 -0400
+++ wp-includes/default-filters.php     2013-05-29 15:31:36.492803981 -0400
@@ -256,6 +256,7 @@
 add_action( 'comment_form',               'wp_comment_form_unfiltered_html_nonce'          );
 add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'                            );
 add_action( 'wp_scheduled_auto_draft_delete', 'wp_delete_auto_drafts'                      );
+add_action( 'transition_comment_status',  'clear_page_of_comment_cache'                    );
 add_action( 'admin_init',                 'send_frame_options_header',               10, 0 );
 add_action( 'importer_scheduled_cleanup', 'wp_delete_attachment'                           );
 add_action( 'upgrader_scheduled_cleanup', 'wp_delete_attachment'                           );
