aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/statement_cache.rb
Commit message (Collapse)AuthorAgeFilesLines
* Ruby 2.7 warning: creating a Proc without a blockutilum2019-02-131-2/+2
| | | | | | | | | | | | | | | | As of [Revision 66772]( https://bugs.ruby-lang.org/projects/ruby-trunk/repository/trunk/revisions/66772) `Proc.new` without giving a block emits `warning: tried to create Proc object without a block`. This commit fixes cases where Rails test suit tickles this warning. See CI logs: https://travis-ci.org/rails/rails/jobs/487205819#L1161-L1190 https://travis-ci.org/rails/rails/jobs/487205821#L1154-1159 https://travis-ci.org/rails/rails/jobs/487205821#L1160-L1169 https://travis-ci.org/rails/rails/jobs/487205821#L1189 https://travis-ci.org/rails/rails/jobs/487254404#L1307-L1416 https://travis-ci.org/rails/rails/jobs/487254405#L1174-L1191
* Ensure `StatementCache#execute` never raises `RangeError`Ryuta Kamizono2019-01-181-0/+2
| | | | | | | | | | | | | Since 31ffbf8d, finder methods no longer raise `RangeError`. So `StatementCache#execute` is the only place to raise the exception for finder queries. `StatementCache` is used for simple equality queries in the codebase. This means that if `StatementCache#execute` raises `RangeError`, the result could always be regarded as empty. So `StatementCache#execute` just return nil in that range error case, and treat that as empty in the caller side, then we can avoid catching the exception in much places.
* Place `PartialQuery` and `PartialQueryCollector` in the same fileRyuta Kamizono2018-09-301-1/+27
|
* Use private attr_readerRyuta Kamizono2018-02-231-2/+1
| | | | | Since #32028, Rails 6 requires Ruby 2.3+. No longer needed workaround for Ruby 2.2 "private attribute?" warning.
* Passing `klass` to `StatementCache.new`Ryuta Kamizono2017-08-041-8/+11
| | | | | | Actually `StatementCache#execute` is always passed the same klass that the owner klass of the connection when the statement cache is created. So passing `klass` to `StatementCache.new` will make more DRY.
* Merge pull request #29842 from kamipo/fix_find_by_with_rangeMatthew Draper2017-08-021-1/+6
|\ | | | | Fix `find_by` with range conditions
| * Fix `find_by` with range conditionsRyuta Kamizono2017-07-201-1/+6
| | | | | | | | | | `StatementCache` doesn't support range conditions. So we need to through the args to `FinderMethods#find_by` if range value is passed.
* | Fix test failures when prepared statements are disabledSean Griffin2017-07-241-11/+9
| | | | | | | | | | | | | | | | | | This also reverts the change to enable prepared statements by default on MySQL (though I suspect we could enable them and it'd be great). This change brings back a collector closer to the old `Bind` collector in Arel. However, this one lives in AR, since this is an AR specific need. Additionally, we only use it for statement caching, since the new substitute collector in Arel is higher performance for most cases.
* | Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-12/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-3/+3
|
* [ci skip] Fix wrong rdoc-ref links, the format is {}[] not []{}Prathamesh Sonpatki2016-09-141-2/+2
|
* Ensure that inverse associations are set before running callbacksSean Griffin2016-08-311-2/+2
| | | | | | | | | | | | | | | | | If a parent association was accessed in an `after_find` or `after_initialize` callback, it would always end up loading the association, and then immediately overwriting the association we just loaded. If this occurred in a way that the parent's `current_scope` was set to eager load the child, this would result in an infinite loop and eventually overflow the stack. For records that are created with `.new`, we have a mechanism to perform an action before the callbacks are run. I've introduced the same code path for records created with `instantiate`, and updated all code which sets inverse instances on newly loaded associations to use this block instead. Fixes #26320.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* Remove `prepare_binds_for_database` internal methodRyuta Kamizono2016-07-281-2/+2
| | | | To avoid relying on the connection adapter for type casting binds.
* Decouple statement cache from connection adapterRyuta Kamizono2016-07-241-7/+6
| | | | | | `StatementCache` is hard-coded in `cacheable_query` and be passed `visitor` and `collector` from connection adapter. Simply it is enough to pass a collected value.
* Ensure prepared statement caching still occurs with Adequate RecordSean Griffin2016-02-111-1/+1
| | | | | | | | | | | | | 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
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-3/+5
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Remove Relation#bind_paramsSean Griffin2015-01-271-9/+9
| | | | | | | | `bound_attributes` is now used universally across the board, removing the need for the conversion layer. These changes are mostly mechanical, with the exception of the log subscriber. Additional, we had to implement `hash` on the attribute objects, so they could be used as a key for query caching.
* Stop passing a column to `quote` when executing from a statement cacheSean Griffin2015-01-101-2/+2
| | | | | | | I'm planning on deprecating the column argument to mirror the deprecation in [arel]. [arel]: https://github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Update the StatementCache documentationRafael Mendonça França2014-11-271-4/+15
|
* StatementCache is private APIRafael Mendonça França2014-11-271-6/+6
| | | | It should not be used in applications
* use an array for bind params to simplify substitutionAaron Patterson2014-04-121-5/+5
|
* decouple the factory method from the constructing modelAaron Patterson2014-04-101-3/+1
| | | | | | The factory method only requires the constructing model to get the connection object. Since the model is available when calling the factory method, we can just pass the appropriate connection in.
* remove intelligence from StatementCache#initializeAaron Patterson2014-04-101-9/+11
|
* stop caching the class on the statement cache objectAaron Patterson2014-04-101-5/+5
|
* fix ivar names and add reader methodsAaron Patterson2014-04-101-7/+6
|
* eagerly build the cacheable query builderAaron Patterson2014-04-101-13/+7
|
* eagerly build the bind mapAaron Patterson2014-04-101-8/+5
|
* eagerly build the relation objectAaron Patterson2014-04-101-8/+2
|
* remove dead codeAaron Patterson2014-04-101-7/+0
|
* speed up parameter substitutionAaron Patterson2014-04-091-2/+12
| | | | | store the offsets of the bind values, then only index to bind value locations before joining the array
* working against arel/collector branchAaron Patterson2014-04-091-4/+4
|
* working against arel/collector branchAaron Patterson2014-04-091-1/+1
|
* fix the method signatureAaron Patterson2014-01-171-1/+1
|
* oops!Aaron Patterson2014-01-171-1/+1
|
* don't cache the connection (because we don't need to)Aaron Patterson2014-01-171-8/+7
|
* remove dead codeAaron Patterson2014-01-171-1/+1
|
* change query strategy based on adapterAaron Patterson2014-01-161-4/+41
|
* use a params hash so we know what bind parameters are usedAaron Patterson2014-01-151-9/+48
|
* fix cache class interfaceAaron Patterson2014-01-141-5/+17
|
* just a testAaron Patterson2013-05-171-6/+2
|
* Initial commit for select statements bindparam implementationNoemj2013-05-151-2/+6
|
* minor edit on StatementCache documentation [ci skip]Francesco Rodriguez2013-04-121-1/+1
|
* Fix StatementCache docs format [ci skip]Francesco Rodriguez2013-04-111-5/+5
|
* Switched to new naming conventionsNoemj2013-04-111-1/+1
| | | | [ci skip]
* Merge pull request #10152 from Noemj/statement_cacheRafael Mendonça França2013-04-101-5/+5
| | | | | | | Statement cache Conflicts: activerecord/CHANGELOG.md