Commit 720aa9e1195a4f14a5f1992c3ef7cfc25ae2accb

Authored by Pius Uzamere
1 parent f7235700

use cached loss count to compute wins + losses

Showing 1 changed file with 4 additions and 4 deletions   Show diff stats
app/models/choice.rb
@@ -23,16 +23,16 @@ class Choice < ActiveRecord::Base @@ -23,16 +23,16 @@ class Choice < ActiveRecord::Base
23 23
24 def wins_plus_losses 24 def wins_plus_losses
25 #(prompts_on_the_left.collect(&:votes_count).sum + prompts_on_the_right.collect(&:votes_count).sum) 25 #(prompts_on_the_left.collect(&:votes_count).sum + prompts_on_the_right.collect(&:votes_count).sum)
26 - Prompt.sum('votes_count', :conditions => "left_choice_id = #{id} OR right_choice_id = #{id}")  
27 - #wins + losses 26 + #Prompt.sum('votes_count', :conditions => "left_choice_id = #{id} OR right_choice_id = #{id}")
  27 + wins + losses
28 end 28 end
29 29
30 def losses 30 def losses
31 - loss_count 31 + loss_count || 0
32 end 32 end
33 33
34 def wins 34 def wins
35 - votes_count 35 + votes_count || 0
36 end 36 end
37 37
38 after_create :generate_prompts 38 after_create :generate_prompts