aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/result.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Make `ActiveRecord::Result#to_a` as alias to `ActiveRecord::Result#to_ary`bogdanvlviv2018-09-201-5/+2
| | | | | | | | | | | | `ActiveRecord::Result#to_a` was introduced in #33912. I would prefer to make `to_a` as alias to the `to_ary` because: - It would be clear for users from https://edgeapi.rubyonrails.org/classes/ActiveRecord/Result.html that `to_a` and `to_ary` are the same - For us it would take less efforts in case if we needed to change the docs or implementation, since the methods are the same Follow up #33912
* Deprecate ActiveRecord::Result#to_hash in favor of #to_aKevin Cheng2018-09-181-2/+10
| | | | | | | method returns an array of hashes, not a hash e.g. Hash.try_convert(result) calls #to_hash and raises a TypeError [Gannon McGibbon + Kevin Cheng]
* Do not recompute lengthschneems2018-08-301-2/+2
| | | | We can get a speed gain by moving the length calculation and assignment out of the loop.
* Fix documentation based on feedbackAaron Patterson2018-06-261-1/+1
|
* Speed up homogeneous AR lists / reduce allocationsAaron Patterson2018-06-251-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit speeds up allocating homogeneous lists of AR objects. We can know if the result set contains an STI column before initializing every AR object, so this change pulls the "does this result set contain an STI column?" test up, then uses a specialized instantiation function. This way we only have to check for an STI column once rather than N times. This change also introduces a new initialization function that is meant for use when allocating AR objects that come from the database. Doing this allows us to eliminate one hash allocation per AR instance. Here is a benchmark: ```ruby require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:" ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :users, force: true do |t| t.string :name t.timestamps null: false end end class User < ActiveRecord::Base; end 2000.times do User.create!(name: "Gorby") end Benchmark.ips do |x| x.report("find") do User.limit(2000).to_a end end ``` Results: Before: ``` [aaron@TC activerecord (master)]$ be ruby -I lib:~/git/allocation_tracer/lib speed.rb Warming up -------------------------------------- find 5.000 i/100ms Calculating ------------------------------------- find 56.192 (± 3.6%) i/s - 285.000 in 5.080940s ``` After: ``` [aaron@TC activerecord (homogeneous-allocation)]$ be ruby -I lib:~/git/allocation_tracer/lib speed.rb Warming up -------------------------------------- find 7.000 i/100ms Calculating ------------------------------------- find 72.204 (± 2.8%) i/s - 364.000 in 5.044592s ```
* Avoid creating temporary arrays in ActiveRecord::Result#cast_values in order ↵Lachlan Sylvester2018-06-191-5/+14
| | | | to speed up pluck
* PERF: avoid allocating column names where possibleSam2018-06-061-1/+1
| | | | | | | | | | | When requesting columns names from database adapters AR:Result would dup/freeze column names, this prefers using fstrings which cuts down on repeat allocations Attributes that are retained keep these fstrings around for the long term Note, this has the highest impact on "short" result sets, eg: Topic.first where you can void allocating the number of columns * String.
* 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
|
* Improve docs for ActiveRecord::Result. [ci skip]Trevor Reiff2017-02-241-1/+12
| | | | Remove styling from `true` and `false`.
* Add `Type.default_value` and use it everywhere for internalRyuta Kamizono2016-08-261-3/+1
| | | | For reduce instantiating `Type::Value`.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-29/+29
|
* Optimize ActiveRecord::Result#lastBenjamin Quorning2016-06-241-1/+2
| | | | | If you only want the last element of a result set, there's no need to create all of hash_rows. Also, add a test.
* Add ActiveRecord::Result#firstBenjamin Quorning2016-06-241-0/+5
| | | | | When you only need the first element of a result set, you shouldn't need to instantiate all of hash_rows.
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-2/+3
| | | | | | | | | | | | | | | | | | | 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
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-1/+1
|
* Revert "Improve performance of AR object instantiation"Sean Griffin2014-11-141-9/+0
| | | | | | | | | | This reverts commit 8fee923888192a658d8823b31e77ed0683dfd665. Conflicts: activerecord/lib/active_record/attribute_set/builder.rb This solution sucks, and is hard to actually apply across the board. Going to try other solutions
* Improve performance of AR object instantiationSean Griffin2014-11-051-0/+9
| | | | | | | We introduced a performance hit by adding an additional iteration through a model's attributes on creation. We don't actually need the values from `Result` to be a hash, we can separate the columns and values and zip them up ourself during the iteration that we have to do.
* add length to ActiveRecord::ResultAaron Patterson2014-10-131-0/+4
|
* Encapsulate knowledge of type objects on `ActiveRecord::Result`Sean Griffin2014-06-221-8/+15
| | | | | | | | | | | | | Attempting to reduce the number of places that care about the details of how type casting occurs. We remove the type casting of the primary key in `JoinDependecy`, rather than encapsulating it. It was originally added for consistency with https://github.com/rails/rails/commit/40898c8c19fa04442fc5f8fb5daf3a8bdb9a1e03#diff-06059df8d3dee3101718fb2c01151ad0R211, but that conditional was later removed in https://github.com/rails/rails/commit/d7ddaa530fd1b94e22d745cbaf2e8a5a34ee9734. What is important is that the same row twice will have the same value for the primary key, which it will.
* Introduce an Attribute object to handle the type casting danceSean Griffin2014-06-131-1/+1
| | | | | | | | | | | | | | | There's a lot more that can be moved to these, but this felt like a good place to introduce the object. Plans are: - Remove all knowledge of type casting from the columns, beyond a reference to the cast_type - Move type_cast_for_database to these objects - Potentially make them mutable, introduce a state machine, and have dirty checking handled here as well - Move `attribute`, `decorate_attribute`, and anything else that modifies types to mess with this object, not the columns hash - Introduce a collection object to manage these, reduce allocations, and not require serializing the types
* Use an actual identity type in AR::Result#identity_typeSean Griffin2014-06-091-1/+1
| | | | | We should be able to rely on this object implenting the full type interface.
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-1/+1
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* Return sized enumerator from Batches#find_eachMarc-Andre Lafortune2014-02-051-1/+1
|
* Also dup `column_types` in AR::Result `initialize_copy`Vipul A M2013-11-101-3/+4
|
* typecast records returned from the db rather than to_sing everythingAaron Patterson2013-10-081-0/+4
|
* Perf: micro optimised Result column hash_row creationSam2013-08-291-1/+15
|
* Added some usage about ActiveRecord::Result [ci skip]kennyj2013-07-231-2/+26
|
* make the identity type a singleton to save on object creationAaron Patterson2013-07-011-0/+6
|
* Change Result#each to return an Enumerator when called without a block.Ben Woosley2013-06-181-1/+5
| | | | As with #10992, this lets us call #with_index, etc on the results.
* Remove ActiveRecord::ModelJon Leighton2012-10-261-1/+1
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* Freeze columns only once per ResultSantiago Pastorino2012-09-201-6/+9
|
* Freeze columns just before using them as hash keysSantiago Pastorino2012-09-201-2/+5
|
* Freeze columns before using them as hash keysJeremy Evans2012-09-131-1/+1
| | | This reduces the number of allocated strings from columns * (rows + 1) to just columns.
* Refactor AR::Result or inherits. Because we have redundant codes aboutkennyj2012-08-221-2/+2
|
* Doc for ActiveRecord::Result empty? methodRob Zolkos2012-05-071-0/+1
|
* moving column types to an ivar on the resultAaron Patterson2012-02-071-8/+5
|
* column types are passed from the result set to the instantiated AR objectAaron Patterson2012-02-071-0/+4
|
* QueryCache will just dup an AR::Result, AR::Result can deep copyAaron Patterson2012-01-311-0/+6
|
* made the result set object act more like an arrayAaron Patterson2012-01-311-0/+19
|
* Remove extra white spaces on ActiveRecord docs.Sebastian Martinez2011-05-231-1/+1
|
* updating the docco for ActiveRecord::ResultAaron Patterson2011-04-111-2/+2
|
* adjust query counts to be consistent across databases, make sure database ↵Aaron Patterson2011-02-041-0/+4
| | | | log the same things
* AR internals expect a normal hash, otherwise there are serialization ↵Aaron Patterson2011-01-051-1/+1
| | | | incompatibilities
* exec returns an AR::ResultAaron Patterson2010-10-261-0/+30