aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
Commit message (Collapse)AuthorAgeFilesLines
* Restore `to_sql` to return only SQL (#29945)Ryuta Kamizono2017-08-181-1/+1
| | | | Because `to_sql` is public API. I introduced `to_sql_and_binds` internal API to return SQL and binds.
* Add missed `require`yui-knk2017-08-071-0/+2
| | | | | `ActiveRecord::ConnectionAdapters::QueryCache::ConnectionPoolConfiguration` depends on `Concurrent::Map`.
* Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Should use the same connection in using query cacheRyuta Kamizono2017-06-291-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_cache_is_available_when_using_a_not_connected_connection` is always failed if running only the test since #29609. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/query_cache_test.rb -n test_cache_is_available_when_using_a_not_connected_connection Using mysql2 Run options: -n test_cache_is_available_when_using_a_not_connected_connection --seed 15043 F Finished in 0.070519s, 14.1806 runs/s, 28.3612 assertions/s. 1) Failure: QueryCacheTest#test_cache_is_available_when_using_a_not_connected_connection [test/cases/query_cache_test.rb:336]: 2 instead of 1 queries were executed. Queries: SELECT `tasks`.* FROM `tasks` WHERE `tasks`.`id` = ? LIMIT ? SET NAMES utf8 COLLATE utf8_unicode_ci, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483. Expected: 1 Actual: 2 1 runs, 2 assertions, 1 failures, 0 errors, 0 skips ``` This failure is due to `LogSubscriber` will use not connected `ActiveRecord::Base.connection` even if `Task.connection` is connected. I fixed to always pass `type_casted_binds` to log subscriber to avoid the issue.
* Remove delegating to arel in a relationRyuta Kamizono2017-06-291-0/+1
| | | | | The delegation was needed since passing `relation` with `relation.bound_attributes`. It should use `relation.arel` in that case.
* Ensure test threads share a DB connectioneileencodes2017-02-201-16/+20
| | | | | | | | | | | | | | | | | | | | | | | This ensures multiple threads inside a transactional test to see consistent database state. When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections. This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other. This code only runs in the fixture setup and teardown so it does not affect real production databases. When a transaction is opened we set `lock_thread` to `Thread.current` so we can keep track of which connection the thread is using. When we rollback the transaction we unlock the thread and then there will be no left-over data in the database because the transaction will roll back the correct connections. [ Eileen M. Uchitelle, Matthew Draper ]
* Configure query caching (per thread) on the connection poolMatthew Draper2016-11-061-0/+27
|
* Merge pull request #26909 from matthewd/query-cache-connectionMatthew Draper2016-11-061-0/+2
|\ | | | | Clear query cache during checkin, instead of an execution callback
| * Clear query cache during checkin, instead of an execution callbackMatthew Draper2016-10-271-0/+2
| | | | | | | | | | | | | | It doesn't make sense for the query cache to persist while a connection moves through the pool and is assigned to a new thread. [Samuel Cochran & Matthew Draper]
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|/
* Preserve cached queries name in AS notificationsJean Boussier2016-09-221-4/+10
|
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-2/+2
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-14/+14
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
|
* Fix `NoMethodError: undefined method `preparable'`Ryuta Kamizono2016-02-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The error occurs with `prepared_statements: false`: ``` $ ARCONN=postgresql bundle exec ruby -w -Itest test/cases/associations_test.rb Using postgresql Run options: --seed 27753 ...E.................................... Finished in 0.713115s, 56.0919 runs/s, 91.1494 assertions/s. 1) Error: AssociationsTest#test_force_reload_is_uncached: NoMethodError: undefined method `preparable' for #<Arel::Visitors::PostgreSQL:0x007f8699702570> /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/querying.rb:39:in `find_by_sql' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:699:in `exec_queries' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/association_relation.rb:32:in `exec_queries' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:580:in `load' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:260:in `records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:256:in `to_a' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:458:in `get_records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:473:in `find_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:412:in `load_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_proxy.rb:45:in `load_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_proxy.rb:983:in `records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/delegation.rb:39:in `each' test/cases/associations_test.rb:116:in `block (2 levels) in test_force_reload_is_uncached' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:32:in `cache' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/query_cache.rb:9:in `cache' test/cases/associations_test.rb:115:in `block in test_force_reload_is_uncached' /Users/kamipo/src/github.com/rails/rails/activesupport/lib/active_support/deprecation/reporting.rb:36:in `silence' /Users/kamipo/src/github.com/rails/rails/activesupport/lib/active_support/deprecation/instance_delegator.rb:19:in `silence' test/cases/associations_test.rb:114:in `test_force_reload_is_uncached' ```
* Ensure prepared statement caching still occurs with Adequate RecordSean Griffin2016-02-111-2/+2
| | | | | | | | | | | | | In Rails 5, we're much more restrictive about when we do or don't cache a prepared statement. In particular, we never cache when we are sending an IN statement or a SQL string literal However, in the case of Adequate Record, we are *always* sending a raw SQL string, and we *always* want to cache the result. Fixes #23507 /cc @tgxworld
* Restore query cache on rollbackFlorian Weingarten2014-12-011-1/+1
|
* Make select_all on query cache accept a Relation without binds.Arthur Neves2014-03-131-0/+1
| | | | | [fixes #14361] [related #13886]
* Currently, we clear query_cache in cache block finish, even if we may ↵Vipul A M2013-12-031-1/+1
| | | | | | already have cache true. This commit takes into account the last cache_enabled value, before clearing query_cache.
* Remove confusing generated-code commentaryJeremy Kemper2013-10-281-4/+4
|
* Merge pull request #11331 from vipulnsward/remove_conditionalAaron Patterson2013-08-071-8/+1
|\ | | | | Remove conditional, results are always an instance of `ActiveRecord::Result`
| * Remove conditional, since results are always an instance of ↵Vipul A M2013-07-061-8/+1
| | | | | | | | `ActiveRecord::Result`
* | Move initializing process for query cache to ↵kennyj2013-07-161-0/+6
|/ | | | ActiveRecord::ConnectionAdapters::QueryCache module.
* updates a dynamic method heredoc docXavier Noria2013-01-281-2/+2
|
* explains why the query cache checks arel.lockedXavier Noria2013-01-281-0/+2
|
* Refactor locked? method in query cacheCarlos Antonio da Silva2012-07-071-5/+2
| | | | Introduced in 75b340d1a4bcf2f1233fb65a15ff6b8059e2230e
* Disable query cache for lock queriesDamir Zekic2012-07-061-1/+9
| | | | Fixes #867
* add :nodoc: to internal implementations [ci skip]Francesco Rodriguez2012-06-221-1/+1
|
* prepared statements can be disabledAaron Patterson2012-02-211-1/+1
|
* QueryCache will just dup an AR::Result, AR::Result can deep copyAaron Patterson2012-01-311-9/+15
|
* query cache instrumentation should included the bindings in the payload ↵Xavier Noria2012-01-301-1/+1
| | | | [closes #4750]
* Make it the responsibility of the connection to hold onto an ARel visitor ↵Jon Leighton2011-08-081-2/+3
| | | | for generating SQL. This improves the code architecture generally, and solves some problems with marshalling. Adapter authors please take note: you now need to define an Adapter.visitor_for method, but it degrades gracefully with a deprecation warning for now.
* introduce a body proxy to ensure that query cache is enabled during streamingAaron Patterson2011-05-021-0/+8
|
* no need to specify selfAaron Patterson2011-01-051-1/+1
|
* select_all() should always return an array, so no need to testAaron Patterson2010-10-271-9/+1
|
* speeding up query cacheAaron Patterson2010-10-271-4/+3
|
* making query cache work with prepared statementsAaron Patterson2010-10-271-6/+7
|
* This method is actually not used, it's implemented on the concrete adaptersSantiago Pastorino2010-08-131-8/+0
| | | | [#5331 state:committed]
* eliminate alias_method_chain from ActiveRecordwycats2010-05-091-17/+10
|
* Change event namespace ordering to most-significant first [#4504 state:resolved]Justin George2010-05-021-1/+1
| | | | | | | | | More work still needs to be done on some of these names (render_template.action_view and render_template!.action_view particularly) but this allows (for example) /^sql/ to subscribe to all the various ORMs without further modification Signed-off-by: José Valim <jose.valim@gmail.com>
* clearing up many warnings, removing unnecessary regular expresion ↵Aaron Patterson2010-04-101-2/+1
| | | | | | comparisons [#4365 state:resolved] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* fix stack trace lines on class_evalSantiago Pastorino2010-04-091-1/+1
| | | | Signed-off-by: José Valim <jose.valim@gmail.com>
* adds missing requires for Object#duplicable?Xavier Noria2010-03-281-0/+2
|
* Move AR logging responsibilities to ActiveRecord::Railties::Subscriber.José Valim2010-01-131-1/+2
|
* Inline code comments for class_eval/module_eval [#1657 state:resolved]Xavier Noria2008-12-281-6/+6
| | | | Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* It is not necessary to store QueryCache in a thread local since the cache is ↵Joshua Peek2008-10-301-27/+14
| | | | local to the connection object which is managed by the connection pool
* Use database name in query cache thread local key [#1283 state:resolved]Joshua Peek2008-10-301-3/+2
|