Skip to content

Commit

Permalink
wow. so optimize. Get big debug queries to lighter.
Browse files Browse the repository at this point in the history
Modifying the process of getting statistical queries in the debug page
so that they use up less memory, process faster, retrieve less fields
and don't uselessly cache. Resolves #314
  • Loading branch information
AramZS committed Jul 29, 2014
1 parent 35ae790 commit ba97dac
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions modules/debugger/debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,55 @@ function count_the_posts($post_type, $date_less = false){
} elseif (!empty($date_less) && $date_less < 12) {
$y = date('Y');
$m = date('m');
$m = $m + $date_less;
$m = (int) $m + (int) $date_less;
} elseif (!empty($date_less) && $date_less >= 12) {
$y = date('Y');
$y = $y - floor($date_less/12);
$m = date('m');
$m = $m - (abs($date_less)-(12*floor($date_less/12)));
}

$posts_per_page = 200;
$query_arg = array(
'post_type' => $post_type,
'year' => $y,
'monthnum' => $m,
'posts_per_page' => -1
'year' => (int) $y,
'monthnum' => (int) $m,
'posts_per_page' => $posts_per_page,
'offset' => 0,
'cache_results' => false,
'no_found_rows' => true,
'fields' => 'ids'
);
$query = new WP_Query($query_arg);
#var_dump($query_arg);
#$query = new WP_Query($query_arg);
#var_dump($query);
$total = 0;
$last_q = $posts_per_page;
while ($last_q >= $posts_per_page){
$count = $this->query_counter($query_arg);
$last_q = $count;
$total += $count;
$query_arg['offset'] = $query_arg['offset']+$posts_per_page;
}

return $query->post_count;
return $total;
}

function query_counter($query_arg, $posts_per_page = 200){
if(empty($query_arg['offset'])){ $query_arg['offset'] = 0; }
if(empty($query_arg['posts_per_page'])){ $query_arg['posts_per_page'] = $posts_per_page; }
$query = new WP_Query($query_arg);
#$offset = 0;
$total = 0;
$pc = $query->post_count;
wp_reset_query();
$total += $pc;
#if ($pc < $posts_per_page){
# return $total;
#} else {
# $query_arg['offset'] = $query_arg['offset']+$posts_per_page;
# $total += $this->query_counter($query_arg);
#}
return $total;
}

function admin_menu_callback() {
Expand Down Expand Up @@ -122,7 +154,7 @@ function admin_menu_callback() {
?><br />
<?php
$feed_item = 'pf_feed_item';
echo 'Month to date Feed Items: ' . $this->count_the_posts($feed_item );
echo 'Month to date Feed Items: ' . $this->count_the_posts($feed_item);
echo '<br />Last month Feed Items: ' . $this->count_the_posts($feed_item, -1 );
#var_dump(wp_count_posts($feed_item));
#var_dump(wp_count_posts('post'));
Expand Down

0 comments on commit ba97dac

Please sign in to comment.