Last active
August 29, 2015 14:27
-
-
Save seth-macpherson/8338cef6974ee4e7cb5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
class QuestionScheduler | |
@queue = :email_notifications | |
MAX_ATTEMPTS = 2 | |
# ============================================================ | |
# When both queries are constrained to :current_enrollments | |
# the results are close with pluck ~2x speed improvement | |
# user system total real | |
# pluck(:id) 65.550000 2.310000 67.860000 ( 69.107931) | |
# select(:id) 119.030000 4.160000 123.190000 (129.350956) | |
# ============================================================ | |
# When not constrained to :current_enrollments the results are | |
# no longer in the same ballpark. See QuestionEmailer line:42 | |
# User.select(:id).find_each(batch_size: 1000) | |
# user system total real | |
# select(:id) 809.560000 7.400000 816.960000 (817.421610) | |
# ============================================================ | |
def self.enqueue_rollovers | |
Benchmark.bm do |x| | |
x.report('pluck uniq') do | |
User.joins(:current_enrollments).uniq.pluck(:id).each do |id| | |
Resque.enqueue(self, id) | |
end | |
end | |
x.report("select id") do | |
User.select(:id).find_each(batch_size: 1000) do |u| | |
Resque.enqueue(self, u.id) | |
end | |
end | |
end | |
rescue => ex | |
Airbrake.notify_or_raise ex | |
end | |
def self.perform(user_id) | |
# do nothing for now | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment