Skip to content

Commit

Permalink
use ActiveRecord#find_each to prevent memory spikes in our workers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwell committed May 20, 2013
1 parent 3a0c989 commit 6691180
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add_invites
def weekly_user_stats
@created_users = User.where("username IS NOT NULL and created_at IS NOT NULL")
@created_users_by_week = Hash.new{ |h,k| h[k] = [] }
@created_users.each do |u|
@created_users.find_each do |u|
unless u.nil?
@created_users_by_week[u.created_at.beginning_of_week.strftime("%Y-%m-%d")].push("#{u.username}")
end
Expand Down
2 changes: 1 addition & 1 deletion app/workers/notify_local_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def perform(user_ids, object_klass, object_id, person_id)
users = User.where(:id => user_ids)
person = Person.find_by_id(person_id)

users.each{|user| Notification.notify(user, object, person) }
users.find_each{|user| Notification.notify(user, object, person) }
end
end
end
2 changes: 1 addition & 1 deletion lib/postzord/receiver/local_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def notify_mentioned_users
# return [void]
def notify_users
return unless @object.respond_to?(:notification_type)
@users.each do |user|
@users.find_each do |user|
Notification.notify(user, @object, @object.author)
end
end
Expand Down

0 comments on commit 6691180

Please sign in to comment.