Commit afa30bcd3b3f60505f8d805cb148991179b8a6f6

Authored by Pius Uzamere
1 parent 17a3fde5

prompt_ids function is too slow, using improved picker

Showing 1 changed file with 9 additions and 1 deletions   Show diff stats
app/models/question.rb
... ... @@ -31,11 +31,19 @@ class Question < ActiveRecord::Base
31 31 return p = prompts.find(prompt_ids.rand)
32 32 end until p.active?
33 33 end
  34 +
  35 + def picked_prompt
  36 + pc = self.prompts_count < 1 ? 2 : self.prompts_count
  37 + begin
  38 + return p = prompts.find(rand(pc-1) + prompts.first.id)
  39 + end until p.active?
  40 + end
  41 +
34 42  
35 43 def picked_prompt_id
36 44 pc = self.prompts_count < 1 ? 2 : self.prompts_count
37 45 begin
38   - return rand(pc-1) + prompts.first.id
  46 + return i = rand(pc-1) + prompts.first.id #try caching this first prompt value at some point
39 47 end until prompts.find(i).active?
40 48 end
41 49  
... ...