Skip to content

Commit ce488d2

Browse files
committed
Rename random method
1 parent f883147 commit ce488d2

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

app/models/user.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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))

config/initializers/git_hub_bub.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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"

test/unit/repo_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)