diff --git fivestar/fivestar.module fivestar/fivestar.module index 52b11a1..44f1872 100644 --- fivestar/fivestar.module +++ fivestar/fivestar.module @@ -776,7 +776,7 @@ function _fivestar_cast_vote($type, $cid, $value, $tag = NULL, $uid = NULL, $res function fivestar_get_votes($type, $cid, $tag = 'vote', $uid = NULL) { global $user; - if (empty($uid)) { + if ($uid !== FALSE && empty($uid)) { $uid = $user->uid; } @@ -1074,8 +1074,6 @@ function fivestar_static($content_type, $content_id, $tag = 'vote', $node_type = 'tag' => 'vote', ); - $votes = fivestar_get_votes($content_type, $content_id, $tag); - if ($content_type == 'node') { // Content type should always be passed to avoid this node load. if (!isset($node_type)) { @@ -1087,6 +1085,13 @@ function fivestar_static($content_type, $content_id, $tag = 'vote', $node_type = $text_display = variable_get('fivestar_text_'. $node_type, 'dual'); $title_display = variable_get('fivestar_title_'. $node_type, 1); + if ($star_display == 'average') { + // Avoid database query of current user vote + $votes = fivestar_get_votes($content_type, $content_id, $tag, FALSE); + } + else { + $votes = fivestar_get_votes($content_type, $content_id, $tag); + } $stars = variable_get('fivestar_stars_'. $node_type, 5); switch ($star_display) { case 'average': @@ -1127,6 +1132,7 @@ function fivestar_static($content_type, $content_id, $tag = 'vote', $node_type = } // Possibly add other content types here (comment, user, etc). else { + $votes = fivestar_get_votes($content_type, $content_id, $tag); $stars = 5; $star_value = $votes['average']['value']; $user_value = $votes['user']['value'];