Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6e5a2cb9
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,发现更多精彩内容 >>
提交
6e5a2cb9
编写于
9月 23, 2013
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove state from the preloader
上级
5b432811
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
28 deletion
+18
-28
activerecord/lib/active_record/associations/preloader.rb
activerecord/lib/active_record/associations/preloader.rb
+7
-17
activerecord/lib/active_record/associations/preloader/through_association.rb
...tive_record/associations/preloader/through_association.rb
+9
-10
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+2
-1
未找到文件。
activerecord/lib/active_record/associations/preloader.rb
浏览文件 @
6e5a2cb9
...
...
@@ -46,8 +46,6 @@ class Preloader #:nodoc:
autoload
:BelongsTo
,
'active_record/associations/preloader/belongs_to'
end
attr_reader
:records
,
:associations
,
:preload_scope
,
:model
# Eager loads the named associations for the given Active Record record(s).
#
# In this description, 'association name' shall refer to the name passed
...
...
@@ -82,28 +80,20 @@ class Preloader #:nodoc:
# [ :books, :author ]
# { author: :avatar }
# [ :books, { author: :avatar } ]
def
initialize
(
records
,
associations
,
preload_scope
=
nil
)
@records
=
Array
.
wrap
(
records
).
compact
.
uniq
@associations
=
Array
.
wrap
(
associations
)
@preload_scope
=
preload_scope
||
NULL_RELATION
@preloaders
=
nil
end
NULL_RELATION
=
Struct
.
new
(
:values
).
new
({})
def
run
preloaders
.
each
(
&
:run
)
end
def
preloaders
return
@preloaders
if
@preloaders
def
preload
(
records
,
associations
,
preload_scope
=
nil
)
records
=
Array
.
wrap
(
records
).
compact
.
uniq
associations
=
Array
.
wrap
(
associations
)
preload_scope
=
preload_scope
||
NULL_RELATION
if
records
.
empty?
@preloaders
=
[]
[]
else
@preloaders
=
associations
.
flat_map
{
|
association
|
associations
.
flat_map
{
|
association
|
preloaders_on
association
,
records
,
preload_scope
}
}
.
each
(
&
:run
)
end
end
...
...
activerecord/lib/active_record/associations/preloader/through_association.rb
浏览文件 @
6e5a2cb9
...
...
@@ -16,10 +16,10 @@ def associated_records_by_owner
return
@associated_records_by_owner
if
@associated_records_by_owner
left_loader
=
Preloader
.
new
(
owners
,
through_reflection
.
name
,
through_scope
)
left_loader
.
run
left_loader
=
Preloader
.
new
left_loader
.
preload
(
owners
,
through_reflection
.
name
,
through_scope
)
should_reset
=
(
through_scope
!=
through_reflection
.
klass
.
unscoped
)
||
(
reflection
.
options
[
:source_type
]
&&
through_reflection
.
collection?
)
...
...
@@ -37,13 +37,12 @@ def associated_records_by_owner
middle_records
=
through_records
.
map
{
|
(
_
,
rec
,
_
)
|
rec
}.
flatten
preloader
=
Preloader
.
new
(
middle_records
,
source_reflection
.
name
,
reflection_scope
)
preloader
=
Preloader
.
new
preloaders
=
preloader
.
preload
(
middle_records
,
source_reflection
.
name
,
reflection_scope
)
preloader
.
run
middle_to_pl
=
preloader
.
preloaders
.
each_with_object
({})
do
|
pl
,
h
|
middle_to_pl
=
preloaders
.
each_with_object
({})
do
|
pl
,
h
|
pl
.
owners
.
each
{
|
middle
|
h
[
middle
]
=
pl
}
...
...
activerecord/lib/active_record/relation.rb
浏览文件 @
6e5a2cb9
...
...
@@ -600,7 +600,8 @@ def exec_queries
preload
=
preload_values
preload
+=
includes_values
unless
eager_loading?
preload
.
each
do
|
associations
|
ActiveRecord
::
Associations
::
Preloader
.
new
(
@records
,
associations
).
run
pl
=
ActiveRecord
::
Associations
::
Preloader
.
new
pl
.
preload
@records
,
associations
end
@records
.
each
{
|
record
|
record
.
readonly!
}
if
readonly_value
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录