mirror of https://github.com/rails/rails
Merge pull request #17820 from fw42/restore_query_cache_on_rollback
Clear query cache on rollback
This commit is contained in:
parent
7d8e56ab07
commit
5dc0bb9203
|
@ -1,3 +1,7 @@
|
||||||
|
* Clear query cache on rollback.
|
||||||
|
|
||||||
|
*Florian Weingarten*
|
||||||
|
|
||||||
* Fixed setting of foreign_key for through associations while building of new record.
|
* Fixed setting of foreign_key for through associations while building of new record.
|
||||||
|
|
||||||
Fixes #12698.
|
Fixes #12698.
|
||||||
|
|
|
@ -273,7 +273,18 @@ module ActiveRecord
|
||||||
|
|
||||||
# Rolls back the transaction (and turns on auto-committing). Must be
|
# Rolls back the transaction (and turns on auto-committing). Must be
|
||||||
# done if the transaction block raises an exception or returns false.
|
# done if the transaction block raises an exception or returns false.
|
||||||
def rollback_db_transaction() end
|
def rollback_db_transaction
|
||||||
|
exec_rollback_db_transaction
|
||||||
|
end
|
||||||
|
|
||||||
|
def exec_rollback_db_transaction() end #:nodoc:
|
||||||
|
|
||||||
|
def rollback_to_savepoint(name = nil)
|
||||||
|
exec_rollback_to_savepoint(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def exec_rollback_to_savepoint(name = nil) #:nodoc:
|
||||||
|
end
|
||||||
|
|
||||||
def default_sequence_name(table, column)
|
def default_sequence_name(table, column)
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -3,7 +3,7 @@ module ActiveRecord
|
||||||
module QueryCache
|
module QueryCache
|
||||||
class << self
|
class << self
|
||||||
def included(base) #:nodoc:
|
def included(base) #:nodoc:
|
||||||
dirties_query_cache base, :insert, :update, :delete
|
dirties_query_cache base, :insert, :update, :delete, :rollback_to_savepoint, :rollback_db_transaction
|
||||||
end
|
end
|
||||||
|
|
||||||
def dirties_query_cache(base, *method_names)
|
def dirties_query_cache(base, *method_names)
|
||||||
|
|
|
@ -9,7 +9,7 @@ module ActiveRecord
|
||||||
execute("SAVEPOINT #{name}")
|
execute("SAVEPOINT #{name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def rollback_to_savepoint(name = current_savepoint_name)
|
def exec_rollback_to_savepoint(name = current_savepoint_name)
|
||||||
execute("ROLLBACK TO SAVEPOINT #{name}")
|
execute("ROLLBACK TO SAVEPOINT #{name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -330,9 +330,6 @@ module ActiveRecord
|
||||||
def create_savepoint(name = nil)
|
def create_savepoint(name = nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rollback_to_savepoint(name = nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
def release_savepoint(name = nil)
|
def release_savepoint(name = nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -328,7 +328,7 @@ module ActiveRecord
|
||||||
execute "COMMIT"
|
execute "COMMIT"
|
||||||
end
|
end
|
||||||
|
|
||||||
def rollback_db_transaction #:nodoc:
|
def exec_rollback_db_transaction #:nodoc:
|
||||||
execute "ROLLBACK"
|
execute "ROLLBACK"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
# Aborts a transaction.
|
# Aborts a transaction.
|
||||||
def rollback_db_transaction
|
def exec_rollback_db_transaction
|
||||||
execute "ROLLBACK"
|
execute "ROLLBACK"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -362,7 +362,7 @@ module ActiveRecord
|
||||||
log('commit transaction',nil) { @connection.commit }
|
log('commit transaction',nil) { @connection.commit }
|
||||||
end
|
end
|
||||||
|
|
||||||
def rollback_db_transaction #:nodoc:
|
def exec_rollback_db_transaction #:nodoc:
|
||||||
log('rollback transaction',nil) { @connection.rollback }
|
log('rollback transaction',nil) { @connection.rollback }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -212,6 +212,38 @@ class QueryCacheTest < ActiveRecord::TestCase
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.configurations = conf
|
ActiveRecord::Base.configurations = conf
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_query_cache_doesnt_leak_cached_results_of_rolled_back_queries
|
||||||
|
ActiveRecord::Base.connection.enable_query_cache!
|
||||||
|
post = Post.first
|
||||||
|
|
||||||
|
Post.transaction do
|
||||||
|
post.update_attributes(title: 'rollback')
|
||||||
|
assert_equal 1, Post.where(title: 'rollback').to_a.count
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal 0, Post.where(title: 'rollback').to_a.count
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.uncached do
|
||||||
|
assert_equal 0, Post.where(title: 'rollback').to_a.count
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
Post.transaction do
|
||||||
|
post.update_attributes(title: 'rollback')
|
||||||
|
assert_equal 1, Post.where(title: 'rollback').to_a.count
|
||||||
|
raise 'broken'
|
||||||
|
end
|
||||||
|
rescue Exception
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal 0, Post.where(title: 'rollback').to_a.count
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.uncached do
|
||||||
|
assert_equal 0, Post.where(title: 'rollback').to_a.count
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class QueryCacheExpiryTest < ActiveRecord::TestCase
|
class QueryCacheExpiryTest < ActiveRecord::TestCase
|
||||||
|
|
Loading…
Reference in New Issue