-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dirties option to Model.uncached #51204
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byroot
reviewed
Feb 27, 2024
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
Show resolved
Hide resolved
jeremy
approved these changes
Feb 28, 2024
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
Outdated
Show resolved
Hide resolved
} | ||
mw.call({}) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great coverage.
djmb
commented
Feb 29, 2024
djmb
force-pushed
the
uncached-dirties
branch
2 times, most recently
from
February 29, 2024 08:50
97126b4
to
cee1f28
Compare
This adds a `dirties` option to `ActiveRecord::Base.uncached` and `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`. Setting `dirties` to `false`, means database writes to the connection pool will not mark any query caches as dirty. The option defaults to `true` which retains the existing behaviour and clears query caches on all connection pools used by the current thread.
yahonda
added a commit
to yahonda/rails
that referenced
this pull request
Mar 3, 2024
This commit addresses these errors since rails#51192 renames `.connection` into `.lease_connection` Follow up rails#51204 ```ruby $ cd activerecord $ bin/test test/cases/query_cache_test.rb -n /uncached_dirties/ Using sqlite3 Run options: -n /uncached_dirties/ --seed 57207 E Error: QueryCacheTest#test_query_cache_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:712:in `block (2 levels) in test_query_cache_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:712:in `block in test_query_cache_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:720:in `test_query_cache_uncached_dirties' bin/test test/cases/query_cache_test.rb:709 E Error: QueryCacheTest#test_query_cache_connection_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:726:in `block (2 levels) in test_query_cache_connection_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:726:in `block in test_query_cache_connection_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:734:in `test_query_cache_connection_uncached_dirties' bin/test test/cases/query_cache_test.rb:723 E Error: QueryCacheTest#test_query_cache_uncached_dirties_disabled_with_nested_cache: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:740:in `block (2 levels) in test_query_cache_uncached_dirties_disabled_with_nested_cache' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:194:in `assert_changes' test/cases/query_cache_test.rb:740:in `block in test_query_cache_uncached_dirties_disabled_with_nested_cache' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:757:in `test_query_cache_uncached_dirties_disabled_with_nested_cache' bin/test test/cases/query_cache_test.rb:737 Finished in 0.134429s, 22.3166 runs/s, 0.0000 assertions/s. 3 runs, 0 assertions, 0 failures, 3 errors, 0 skips $ ```
4 tasks
viralpraxis
pushed a commit
to viralpraxis/rails
that referenced
this pull request
Mar 24, 2024
This adds a `dirties` option to `ActiveRecord::Base.uncached` and `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`. Setting `dirties` to `false`, means database writes to the connection pool will not mark any query caches as dirty. The option defaults to `true` which retains the existing behaviour and clears query caches on all connection pools used by the current thread. Co-authored-by: Jeremy Daer <jeremy@rubyonrails.org>
viralpraxis
pushed a commit
to viralpraxis/rails
that referenced
this pull request
Mar 24, 2024
This commit addresses these errors since rails#51192 renames `.connection` into `.lease_connection` Follow up rails#51204 ```ruby $ cd activerecord $ bin/test test/cases/query_cache_test.rb -n /uncached_dirties/ Using sqlite3 Run options: -n /uncached_dirties/ --seed 57207 E Error: QueryCacheTest#test_query_cache_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:712:in `block (2 levels) in test_query_cache_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:712:in `block in test_query_cache_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:720:in `test_query_cache_uncached_dirties' bin/test test/cases/query_cache_test.rb:709 E Error: QueryCacheTest#test_query_cache_connection_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:726:in `block (2 levels) in test_query_cache_connection_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:726:in `block in test_query_cache_connection_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:734:in `test_query_cache_connection_uncached_dirties' bin/test test/cases/query_cache_test.rb:723 E Error: QueryCacheTest#test_query_cache_uncached_dirties_disabled_with_nested_cache: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:740:in `block (2 levels) in test_query_cache_uncached_dirties_disabled_with_nested_cache' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:194:in `assert_changes' test/cases/query_cache_test.rb:740:in `block in test_query_cache_uncached_dirties_disabled_with_nested_cache' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:757:in `test_query_cache_uncached_dirties_disabled_with_nested_cache' bin/test test/cases/query_cache_test.rb:737 Finished in 0.134429s, 22.3166 runs/s, 0.0000 assertions/s. 3 runs, 0 assertions, 0 failures, 3 errors, 0 skips $ ```
fractaledmind
pushed a commit
to fractaledmind/rails
that referenced
this pull request
May 13, 2024
This adds a `dirties` option to `ActiveRecord::Base.uncached` and `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`. Setting `dirties` to `false`, means database writes to the connection pool will not mark any query caches as dirty. The option defaults to `true` which retains the existing behaviour and clears query caches on all connection pools used by the current thread. Co-authored-by: Jeremy Daer <jeremy@rubyonrails.org>
fractaledmind
pushed a commit
to fractaledmind/rails
that referenced
this pull request
May 13, 2024
This commit addresses these errors since rails#51192 renames `.connection` into `.lease_connection` Follow up rails#51204 ```ruby $ cd activerecord $ bin/test test/cases/query_cache_test.rb -n /uncached_dirties/ Using sqlite3 Run options: -n /uncached_dirties/ --seed 57207 E Error: QueryCacheTest#test_query_cache_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:712:in `block (2 levels) in test_query_cache_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:712:in `block in test_query_cache_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:720:in `test_query_cache_uncached_dirties' bin/test test/cases/query_cache_test.rb:709 E Error: QueryCacheTest#test_query_cache_connection_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:726:in `block (2 levels) in test_query_cache_connection_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:726:in `block in test_query_cache_connection_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:734:in `test_query_cache_connection_uncached_dirties' bin/test test/cases/query_cache_test.rb:723 E Error: QueryCacheTest#test_query_cache_uncached_dirties_disabled_with_nested_cache: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:740:in `block (2 levels) in test_query_cache_uncached_dirties_disabled_with_nested_cache' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:194:in `assert_changes' test/cases/query_cache_test.rb:740:in `block in test_query_cache_uncached_dirties_disabled_with_nested_cache' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:757:in `test_query_cache_uncached_dirties_disabled_with_nested_cache' bin/test test/cases/query_cache_test.rb:737 Finished in 0.134429s, 22.3166 runs/s, 0.0000 assertions/s. 3 runs, 0 assertions, 0 failures, 3 errors, 0 skips $ ```
xjunior
pushed a commit
to xjunior/rails
that referenced
this pull request
Jun 9, 2024
This adds a `dirties` option to `ActiveRecord::Base.uncached` and `ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`. Setting `dirties` to `false`, means database writes to the connection pool will not mark any query caches as dirty. The option defaults to `true` which retains the existing behaviour and clears query caches on all connection pools used by the current thread. Co-authored-by: Jeremy Daer <jeremy@rubyonrails.org>
xjunior
pushed a commit
to xjunior/rails
that referenced
this pull request
Jun 9, 2024
This commit addresses these errors since rails#51192 renames `.connection` into `.lease_connection` Follow up rails#51204 ```ruby $ cd activerecord $ bin/test test/cases/query_cache_test.rb -n /uncached_dirties/ Using sqlite3 Run options: -n /uncached_dirties/ --seed 57207 E Error: QueryCacheTest#test_query_cache_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:712:in `block (2 levels) in test_query_cache_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:712:in `block in test_query_cache_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:720:in `test_query_cache_uncached_dirties' bin/test test/cases/query_cache_test.rb:709 E Error: QueryCacheTest#test_query_cache_connection_uncached_dirties: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:726:in `block (2 levels) in test_query_cache_connection_uncached_dirties' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:241:in `assert_no_changes' test/cases/query_cache_test.rb:726:in `block in test_query_cache_connection_uncached_dirties' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:734:in `test_query_cache_connection_uncached_dirties' bin/test test/cases/query_cache_test.rb:723 E Error: QueryCacheTest#test_query_cache_uncached_dirties_disabled_with_nested_cache: NoMethodError: undefined method `connection' for class ActiveRecord::Base lib/active_record/dynamic_matchers.rb:22:in `method_missing' test/cases/query_cache_test.rb:740:in `block (2 levels) in test_query_cache_uncached_dirties_disabled_with_nested_cache' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/testing/assertions.rb:194:in `assert_changes' test/cases/query_cache_test.rb:740:in `block in test_query_cache_uncached_dirties_disabled_with_nested_cache' test/cases/query_cache_test.rb:771:in `block (2 levels) in middleware' /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/execution_wrapper.rb:91:in `wrap' test/cases/query_cache_test.rb:771:in `block in middleware' test/cases/query_cache_test.rb:757:in `test_query_cache_uncached_dirties_disabled_with_nested_cache' bin/test test/cases/query_cache_test.rb:737 Finished in 0.134429s, 22.3166 runs/s, 0.0000 assertions/s. 3 runs, 0 assertions, 0 failures, 3 errors, 0 skips $ ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
This is an alternative to #50721.
For Solid Cache, we want to be able to read and write from the cache database without using the query cache.
We also don't want to expire the query cache on other connection pools when we write. Writing to the Rails cache shouldn't invalidate the main query cache.
cc @byroot, @jeremy
Detail
This adds a
dirties
option toActiveRecord::Base.uncached
andActiveRecord::ConnectionAdapters::ConnectionPool#uncached
.Setting
dirties
tofalse
, means database writes to the connection pool will not mark any query caches as dirty.The option defaults to
true
which retains the existing behaviour and clears query caches on all connection pools used by the current thread.Additional information
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]