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 | 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], :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 | 33 | end |
| 34 | 34 | memoize :picked_prompt |
| 35 | 35 | |
| ... | ... | @@ -48,12 +48,10 @@ class Question < ActiveRecord::Base |
| 48 | 48 | end |
| 49 | 49 | |
| 50 | 50 | def left_choice_text(prompt = nil) |
| 51 | - prompt ||= prompts.first#prompts.pick | |
| 52 | 51 | picked_prompt.left_choice.item.data |
| 53 | 52 | end |
| 54 | 53 | |
| 55 | 54 | def right_choice_text(prompt = nil) |
| 56 | - prompt ||= prompts.first | |
| 57 | 55 | picked_prompt.right_choice.item.data |
| 58 | 56 | end |
| 59 | 57 | ... | ... |
| ... | ... | @@ -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 | ... | ... |