Skip to content

Commit

Permalink
fix cache set of single answer content
Browse files Browse the repository at this point in the history
  • Loading branch information
rambuvn committed Mar 3, 2015
1 parent be89f15 commit 3b746dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions inc/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,8 @@ function dwqa_get_the_best_answer( $question_id = false ) {
}

$answer_id = wp_cache_get( 'dwqa-best-answer-for-' . $question_id, 'dwqa' );
if ( false == $answer_id ) {

if ( ! $answer_id ) {
global $wpdb;
$query = "SELECT `post_id` FROM `{$wpdb->postmeta}`
WHERE `post_id` IN (
Expand All @@ -1085,11 +1085,12 @@ function dwqa_get_the_best_answer( $question_id = false ) {
ORDER BY CAST( `meta_value` as DECIMAL ) DESC LIMIT 0,1";

$answer_id = $wpdb->get_var( $query );

if ( ! $answer_id ) {
$answer_id = -1;
}
wp_cache_set( 'dwqa-best-answer-for-'.$question_id, $answer_id, 'dwqa', 21600 );
}


if ( $answer_id && ( int ) dwqa_vote_count( $answer_id ) > 2 ) {
return $answer_id;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function filter_question_width_index_table() {

// Page navigation
$total_question = wp_cache_get( 'dwqa_total_question', 'dwqa' );
if ( ! $total_question ) {
if ( ! $total_question && $total_question != 0 ) {
$total_question = $wpdb->get_var( "SELECT count(*) FROM {$table} " . $join . $where . $order );
wp_cache_add( 'dwqa_total_question', $total_question, 'dwqa' );
}
Expand Down
1 change: 0 additions & 1 deletion inc/templates/default/content-answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
<strong>&sdot; </strong> <?php _e( 'Draft', 'dwqa' ); ?>
<?php } ?>
</div><!-- Answer Author -->

</header>
<div class="dwqa-content">
<?php if ( dwqa_is_answer_flag( $answer_id ) ) { ?>
Expand Down

0 comments on commit 3b746dd

Please sign in to comment.