Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
032f502f
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
032f502f
编写于
5月 30, 2012
作者:
V
Vijay Dev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
copy edit the batches docs [ci skip]
上级
2adba2e2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
7 addition
and
9 deletion
+7
-9
activerecord/lib/active_record/relation/batches.rb
activerecord/lib/active_record/relation/batches.rb
+7
-9
未找到文件。
activerecord/lib/active_record/relation/batches.rb
浏览文件 @
032f502f
...
...
@@ -3,15 +3,13 @@
module
ActiveRecord
module
Batches
# Looping through a collection of records from the database
# (using the +all+ method, for example) could be too straneous to your
# memory if you have large amounts of them since it will try
# to instantiate all the objects of it at once.
# (using the +all+ method, for example) is very inefficient
# since it will try to instantiate all the objects at once.
#
# If that's the case, batch processing methods allow you to still work
# with all the records found by the find +options+ but using groups of
# a batch size (defaulting to 1000) at a time, greatly reducing the use of memory.
# In that case, batch processing methods allow you to work
# with the records in batches, thereby greatly reducing memory consumption.
#
# The
find_each method performs by using +find_in_batches+
with a batch size of 1000 (or as
# The
<tt>find_each</tt> method uses <tt>find_in_batches</tt>
with a batch size of 1000 (or as
# specified by the <tt>:batch_size</tt> option).
#
# Person.all.find_each do |person|
...
...
@@ -22,7 +20,7 @@ module Batches
# person.party_all_night!
# end
#
#
If needed, you can also send
the <tt>:start</tt> option to specify
#
You can also pass
the <tt>:start</tt> option to specify
# an offset to control the starting point.
def
find_each
(
options
=
{})
find_in_batches
(
options
)
do
|
records
|
...
...
@@ -52,7 +50,7 @@ def find_each(options = {})
# group.each { |person| person.party_all_night! }
# end
#
# # Let's process the next 2000
party guy
s
# # Let's process the next 2000
record
s
# Person.all.find_in_batches(start: 2000, batch_size: 2000) do |group|
# group.each { |person| person.party_all_night! }
# end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录