Commit 26d83a875c8ba890f8c3fcfe886eee4efb55f7b2
1 parent
968b9545
Exists in
master
and in
1 other branch
adding eager loading and getting rid of unnecessary score computation
Showing
3 changed files
with
3 additions
and
3 deletions
Show diff stats
app/controllers/prompts_controller.rb
... | ... | @@ -61,7 +61,7 @@ class PromptsController < InheritedResources::Base |
61 | 61 | raise "need to specify either ':left' or ':right' as a direction" |
62 | 62 | end |
63 | 63 | |
64 | - @prompt.choices.each(&:compute_score!) | |
64 | + #@prompt.choices.each(&:compute_score!) | |
65 | 65 | respond_to do |format| |
66 | 66 | if successful |
67 | 67 | format.xml { render :xml => @question.picked_prompt.to_xml(:methods => [:left_choice_text, :right_choice_text, :left_choice_id, :right_choice_id]), :status => :ok } | ... | ... |
app/models/question.rb
... | ... | @@ -29,7 +29,7 @@ class Question < ActiveRecord::Base |
29 | 29 | def picked_prompt(rank = 2) |
30 | 30 | raise NotImplementedError.new("Sorry, we currently only support pairwise prompts. Rank of the prompt must be 2.") unless rank == 2 |
31 | 31 | choice_id_array = distinct_array_of_choice_ids(rank) |
32 | - @p = prompts.find_or_create_by_left_choice_id_and_right_choice_id(choice_id_array[0], choice_id_array[1]) | |
32 | + @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 }]) | |
33 | 33 | end |
34 | 34 | memoize :picked_prompt |
35 | 35 | ... | ... |
app/models/visitor.rb
... | ... | @@ -31,7 +31,7 @@ class Visitor < ActiveRecord::Base |
31 | 31 | # choice.score = choice.compute_score |
32 | 32 | # logger.info "Just computed the score for that choice and it's apparently #{choice.score}" |
33 | 33 | # choice.save! |
34 | - logger.info "Saved. That choice's score is still #{choice.score}" | |
34 | + #logger.info "Saved. That choice's score is still #{choice.score}" | |
35 | 35 | other_choices = choices - [choice] |
36 | 36 | other_choices.each {|c| c.lose! } |
37 | 37 | end | ... | ... |