# Thanks Jamis
class << ActiveRecord::Base
def each(limit = 1000)
rows = connection.select_all "select id from #{table_name} where id > 0 limit #{limit}"
while rows.any?
rows.each { |record| yield record }
rows = connection.select_all "select id from #{table_name} where id > #{rows.last['id']} limit #{limit}"
end
self
end
end
# Warming the cache
models = Dir["#{RAILS_ROOT}/app/models/**.rb"]
models.map! { |dir| File.basename(dir, '.rb').classify.constantize }
models.each do |model|
model.each { |record| model.get_cache(record['id']) }
end