Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6ed18732
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,发现更多精彩内容 >>
提交
6ed18732
编写于
6月 19, 2017
作者:
R
Rafael França
提交者:
Rafael Mendonça França
6月 19, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #29454 from kamipo/fix_exists_queries_with_cache
Fix `Relation#exists?` queries with query cache
上级
272cf003
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
51 deletion
+46
-51
activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb
...e_record/connection_adapters/mysql/database_statements.rb
+0
-19
activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
...ord/connection_adapters/postgresql/database_statements.rb
+0
-32
activerecord/test/cases/query_cache_test.rb
activerecord/test/cases/query_cache_test.rb
+46
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb
浏览文件 @
6ed18732
...
...
@@ -13,15 +13,6 @@ def select_all(arel, name = nil, binds = [], preparable: nil) # :nodoc:
result
end
# Returns an array of arrays containing the field values.
# Order is the same as that returned by +columns+.
def
select_rows
(
arel
,
name
=
nil
,
binds
=
[])
# :nodoc:
select_result
(
arel
,
name
,
binds
)
do
|
result
|
@connection
.
next_result
while
@connection
.
more_results?
result
.
to_a
end
end
# Executes the SQL statement in the context of this connection.
def
execute
(
sql
,
name
=
nil
)
# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
...
...
@@ -58,16 +49,6 @@ def last_inserted_id(result)
@connection
.
last_id
end
def
select_result
(
arel
,
name
,
binds
)
arel
,
binds
=
binds_from_relation
(
arel
,
binds
)
sql
=
to_sql
(
arel
,
binds
)
if
without_prepared_statement?
(
binds
)
execute_and_free
(
sql
,
name
)
{
|
result
|
yield
result
}
else
exec_stmt_and_free
(
sql
,
name
,
binds
,
cache_stmt:
true
)
{
|
_
,
result
|
yield
result
}
end
end
def
exec_stmt_and_free
(
sql
,
name
,
binds
,
cache_stmt:
false
)
# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
# made since we established the connection
...
...
activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
浏览文件 @
6ed18732
...
...
@@ -7,30 +7,6 @@ def explain(arel, binds = [])
PostgreSQL
::
ExplainPrettyPrinter
.
new
.
pp
(
exec_query
(
sql
,
"EXPLAIN"
,
binds
))
end
def
select_value
(
arel
,
name
=
nil
,
binds
=
[])
# :nodoc:
select_result
(
arel
,
name
,
binds
)
do
|
result
|
result
.
getvalue
(
0
,
0
)
if
result
.
ntuples
>
0
&&
result
.
nfields
>
0
end
end
def
select_values
(
arel
,
name
=
nil
,
binds
=
[])
# :nodoc:
select_result
(
arel
,
name
,
binds
)
do
|
result
|
if
result
.
nfields
>
0
result
.
column_values
(
0
)
else
[]
end
end
end
# Executes a SELECT query and returns an array of rows. Each row is an
# array of field values.
def
select_rows
(
arel
,
name
=
nil
,
binds
=
[])
# :nodoc:
select_result
(
arel
,
name
,
binds
)
do
|
result
|
result
.
values
end
end
# The internal PostgreSQL identifier of the money data type.
MONEY_COLUMN_TYPE_OID
=
790
#:nodoc:
# The internal PostgreSQL identifier of the BYTEA data type.
...
...
@@ -175,14 +151,6 @@ def exec_rollback_db_transaction
def
suppress_composite_primary_key
(
pk
)
pk
unless
pk
.
is_a?
(
Array
)
end
def
select_result
(
arel
,
name
,
binds
)
arel
,
binds
=
binds_from_relation
(
arel
,
binds
)
sql
=
to_sql
(
arel
,
binds
)
execute_and_clear
(
sql
,
name
,
binds
)
do
|
result
|
yield
result
end
end
end
end
end
...
...
activerecord/test/cases/query_cache_test.rb
浏览文件 @
6ed18732
...
...
@@ -204,6 +204,52 @@ def test_count_queries_with_cache
end
end
def
test_exists_queries_with_cache
Post
.
cache
do
assert_queries
(
1
)
{
Post
.
exists?
;
Post
.
exists?
}
end
end
def
test_select_all_with_cache
Post
.
cache
do
assert_queries
(
1
)
do
2
.
times
{
Post
.
connection
.
select_all
(
Post
.
all
)
}
end
end
end
def
test_select_one_with_cache
Post
.
cache
do
assert_queries
(
1
)
do
2
.
times
{
Post
.
connection
.
select_one
(
Post
.
all
)
}
end
end
end
def
test_select_value_with_cache
Post
.
cache
do
assert_queries
(
1
)
do
2
.
times
{
Post
.
connection
.
select_value
(
Post
.
all
)
}
end
end
end
def
test_select_values_with_cache
Post
.
cache
do
assert_queries
(
1
)
do
2
.
times
{
Post
.
connection
.
select_values
(
Post
.
all
)
}
end
end
end
def
test_select_rows_with_cache
Post
.
cache
do
assert_queries
(
1
)
do
2
.
times
{
Post
.
connection
.
select_rows
(
Post
.
all
)
}
end
end
end
def
test_query_cache_dups_results_correctly
Task
.
cache
do
now
=
Time
.
now
.
utc
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录