From 66911801f7742514a2bff1c2cf0ee08872c07b38 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sun, 19 May 2013 20:33:04 -0700 Subject: [PATCH] use ActiveRecord#find_each to prevent memory spikes in our workers --- app/controllers/admins_controller.rb | 2 +- app/workers/notify_local_users.rb | 2 +- lib/postzord/receiver/local_batch.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index e8b0a0aa6..7c56bbbc8 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -30,7 +30,7 @@ class AdminsController < ApplicationController 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 diff --git a/app/workers/notify_local_users.rb b/app/workers/notify_local_users.rb index 08466aba2..1f6200114 100644 --- a/app/workers/notify_local_users.rb +++ b/app/workers/notify_local_users.rb @@ -17,7 +17,7 @@ module Workers 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 diff --git a/lib/postzord/receiver/local_batch.rb b/lib/postzord/receiver/local_batch.rb index 9acf0cc92..454121f6f 100644 --- a/lib/postzord/receiver/local_batch.rb +++ b/lib/postzord/receiver/local_batch.rb @@ -60,7 +60,7 @@ class Postzord::Receiver::LocalBatch < Postzord::Receiver # 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