File tree Expand file tree Collapse file tree 3 files changed +6
-3
lines changed Expand file tree Collapse file tree 3 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,10 @@ def auth_is_valid?
103103 end
104104
105105 @@max_id = nil
106- def self . random
106+
107+ # Much faster than order("RANDOM()") but it's
108+ # not guaranteed to return results
109+ def self . fast_rand
107110 @@max_id = self . maximum ( :id ) if @@max_id . nil?
108111
109112 where ( "id >= ?" , Random . new . rand ( 1 ..@@max_id ) )
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def call
3333 @mutex . synchronize do
3434 return if @keys . any?
3535
36- @keys = User . random . where . not ( token : nil ) . limit ( 5000 ) . pluck ( :token )
36+ @keys = User . fast_rand . where . not ( token : nil ) . limit ( 5000 ) . pluck ( :token )
3737
3838 if @keys . empty? && User . where . not ( token : nil ) . empty?
3939 raise "No users with tokens in the database"
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ class RepoTest < ActiveSupport::TestCase
4545 repo = Repo . create user_name : 'Refinery' , name : 'Refinerycms'
4646 repo . users << users ( :jroes )
4747 repo . users << users ( :schneems )
48- repo . subscriber_count == 2
48+ repo . subscribers_count == 2
4949 end
5050 end
5151
You can’t perform that action at this time.
0 commit comments