Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ac65e560
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
ac65e560
编写于
5月 14, 2020
作者:
R
Ryuta Kamizono
提交者:
GitHub
5月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #39269 from kamipo/improve_performance_loaded_association_first
Improve performance for loaded association's `first`
上级
1c3e75bf
c2a3fdc0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
12 deletion
+16
-12
activerecord/lib/active_record/associations/collection_proxy.rb
...record/lib/active_record/associations/collection_proxy.rb
+4
-0
activerecord/lib/active_record/relation/finder_methods.rb
activerecord/lib/active_record/relation/finder_methods.rb
+12
-12
未找到文件。
activerecord/lib/active_record/associations/collection_proxy.rb
浏览文件 @
ac65e560
...
...
@@ -1103,6 +1103,10 @@ def reset_scope # :nodoc:
delegate
(
*
delegate_methods
,
to: :scope
)
private
def
check_reorder_deprecation
super
unless
loaded?
end
def
find_nth_with_limit
(
index
,
limit
)
load_target
if
find_from_target?
super
...
...
activerecord/lib/active_record/relation/finder_methods.rb
浏览文件 @
ac65e560
...
...
@@ -114,14 +114,7 @@ def take!
# Person.first(3) # returns the first three objects fetched by SELECT * FROM people ORDER BY people.id LIMIT 3
#
def
first
(
limit
=
nil
)
if
!
order_values
.
empty?
&&
order_values
.
all?
(
&
:blank?
)
blank_value
=
order_values
.
first
ActiveSupport
::
Deprecation
.
warn
(
<<~
MSG
.
squish
)
`.reorder(
#{
blank_value
.
inspect
}
)` with `.first` / `.first!` no longer
takes non-deterministic result in Rails 6.2.
To continue taking non-deterministic result, use `.take` / `.take!` instead.
MSG
end
check_reorder_deprecation
if
limit
find_nth_with_limit
(
0
,
limit
)
...
...
@@ -355,8 +348,15 @@ def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_siz
end
private
def
offset_index
offset_value
||
0
def
check_reorder_deprecation
if
!
order_values
.
empty?
&&
order_values
.
all?
(
&
:blank?
)
blank_value
=
order_values
.
first
ActiveSupport
::
Deprecation
.
warn
(
<<~
MSG
.
squish
)
`.reorder(
#{
blank_value
.
inspect
}
)` with `.first` / `.first!` no longer
takes non-deterministic result in Rails 6.2.
To continue taking non-deterministic result, use `.take` / `.take!` instead.
MSG
end
end
def
construct_relation_for_exists
(
conditions
)
...
...
@@ -518,7 +518,7 @@ def find_take_with_limit(limit)
end
def
find_nth
(
index
)
@offsets
[
offset_index
+
index
]
||=
find_nth_with_limit
(
index
,
1
).
first
@offsets
[
index
]
||=
find_nth_with_limit
(
index
,
1
).
first
end
def
find_nth_with_limit
(
index
,
limit
)
...
...
@@ -532,7 +532,7 @@ def find_nth_with_limit(index, limit)
end
if
limit
>
0
relation
=
relation
.
offset
(
offset_index
+
index
)
unless
index
.
zero?
relation
=
relation
.
offset
(
(
offset_value
||
0
)
+
index
)
unless
index
.
zero?
relation
.
limit
(
limit
).
to_a
else
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录