From 26d83a875c8ba890f8c3fcfe886eee4efb55f7b2 Mon Sep 17 00:00:00 2001 From: Pius Uzamere Date: Sat, 19 Dec 2009 00:25:48 -0500 Subject: [PATCH] adding eager loading and getting rid of unnecessary score computation --- app/controllers/prompts_controller.rb | 2 +- app/models/question.rb | 2 +- app/models/visitor.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/prompts_controller.rb b/app/controllers/prompts_controller.rb index c0c0a65..a51a6fa 100644 --- a/app/controllers/prompts_controller.rb +++ b/app/controllers/prompts_controller.rb @@ -61,7 +61,7 @@ class PromptsController < InheritedResources::Base raise "need to specify either ':left' or ':right' as a direction" end - @prompt.choices.each(&:compute_score!) + #@prompt.choices.each(&:compute_score!) respond_to do |format| if successful format.xml { render :xml => @question.picked_prompt.to_xml(:methods => [:left_choice_text, :right_choice_text, :left_choice_id, :right_choice_id]), :status => :ok } diff --git a/app/models/question.rb b/app/models/question.rb index efcc706..9939b1d 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -29,7 +29,7 @@ class Question < ActiveRecord::Base def picked_prompt(rank = 2) raise NotImplementedError.new("Sorry, we currently only support pairwise prompts. Rank of the prompt must be 2.") unless rank == 2 choice_id_array = distinct_array_of_choice_ids(rank) - @p = prompts.find_or_create_by_left_choice_id_and_right_choice_id(choice_id_array[0], choice_id_array[1]) + @p = prompts.find_or_create_by_left_choice_id_and_right_choice_id(choice_id_array[0], choice_id_array[1], :include => [{ :left_choice => :item }, { :right_choice => :item }]) end memoize :picked_prompt diff --git a/app/models/visitor.rb b/app/models/visitor.rb index 84b14b8..d59c89d 100644 --- a/app/models/visitor.rb +++ b/app/models/visitor.rb @@ -31,7 +31,7 @@ class Visitor < ActiveRecord::Base # choice.score = choice.compute_score # logger.info "Just computed the score for that choice and it's apparently #{choice.score}" # choice.save! - logger.info "Saved. That choice's score is still #{choice.score}" + #logger.info "Saved. That choice's score is still #{choice.score}" other_choices = choices - [choice] other_choices.each {|c| c.lose! } end -- libgit2 0.21.2