提交 6bb76f1a 编写于 作者: R Rafael França 提交者: Rafael Mendonça França

Merge pull request #29454 from kamipo/fix_exists_queries_with_cache

Fix `Relation#exists?` queries with query cache
上级 f5f213cc
......@@ -13,15 +13,6 @@ def select_all(arel, name = nil, binds = [], preparable: nil)
result
end
# Returns an array of arrays containing the field values.
# Order is the same as that returned by +columns+.
def select_rows(sql, name = nil, binds = [])
select_result(sql, 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
......
......@@ -7,34 +7,6 @@ def explain(arel, binds = [])
PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
end
def select_value(arel, name = nil, binds = [])
arel, binds = binds_from_relation arel, binds
sql = to_sql(arel, binds)
execute_and_clear(sql, name, binds) do |result|
result.getvalue(0, 0) if result.ntuples > 0 && result.nfields > 0
end
end
def select_values(arel, name = nil, binds = [])
arel, binds = binds_from_relation arel, binds
sql = to_sql(arel, binds)
execute_and_clear(sql, 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(sql, name = nil, binds = [])
execute_and_clear(sql, 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.
......
......@@ -167,6 +167,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.
先完成此消息的编辑!
想要评论请 注册