Commit 5f252b60c7f9e1ca8d7c448374068ab54b87c076
1 parent
26d83a87
Exists in
master
and in
1 other branch
more indexing, less unnecessary action
Showing
2 changed files
with
10 additions
and
3 deletions
Show diff stats
app/models/question.rb
| @@ -29,7 +29,7 @@ class Question < ActiveRecord::Base | @@ -29,7 +29,7 @@ class Question < ActiveRecord::Base | ||
| 29 | def picked_prompt(rank = 2) | 29 | def picked_prompt(rank = 2) |
| 30 | raise NotImplementedError.new("Sorry, we currently only support pairwise prompts. Rank of the prompt must be 2.") unless rank == 2 | 30 | raise NotImplementedError.new("Sorry, we currently only support pairwise prompts. Rank of the prompt must be 2.") unless rank == 2 |
| 31 | choice_id_array = distinct_array_of_choice_ids(rank) | 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], :include => [{ :left_choice => :item }, { :right_choice => :item }]) | 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 | end | 33 | end |
| 34 | memoize :picked_prompt | 34 | memoize :picked_prompt |
| 35 | 35 | ||
| @@ -48,12 +48,10 @@ class Question < ActiveRecord::Base | @@ -48,12 +48,10 @@ class Question < ActiveRecord::Base | ||
| 48 | end | 48 | end |
| 49 | 49 | ||
| 50 | def left_choice_text(prompt = nil) | 50 | def left_choice_text(prompt = nil) |
| 51 | - prompt ||= prompts.first#prompts.pick | ||
| 52 | picked_prompt.left_choice.item.data | 51 | picked_prompt.left_choice.item.data |
| 53 | end | 52 | end |
| 54 | 53 | ||
| 55 | def right_choice_text(prompt = nil) | 54 | def right_choice_text(prompt = nil) |
| 56 | - prompt ||= prompts.first | ||
| 57 | picked_prompt.right_choice.item.data | 55 | picked_prompt.right_choice.item.data |
| 58 | end | 56 | end |
| 59 | 57 |
| @@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
| 1 | +class CreateMorePromptIndexes < ActiveRecord::Migration | ||
| 2 | + def self.up | ||
| 3 | + add_index :prompts, [:left_choice_id, :right_choice_id, :question_id] | ||
| 4 | + end | ||
| 5 | + | ||
| 6 | + def self.down | ||
| 7 | + remove_index :prompts, [:left_choice_id, :right_choice_id, :question_id] | ||
| 8 | + end | ||
| 9 | +end |