aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/result_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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 ```
* 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
|
* Remove checks for Enumerator#size methodEugene Kenny2017-04-251-4/+2
| | | | | | | | The Enumerator#size method was introduced in Ruby 2.0. These tests were added when Rails 4.1 was current, and Ruby 1.9.3 was still supported. Since Rails 5 only Ruby >= 2.2.2 is supported, so the checks are no longer necessary.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-5/+5
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-11/+11
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Optimize ActiveRecord::Result#lastBenjamin Quorning2016-06-241-0/+5
| | | | | 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.
* add length to ActiveRecord::ResultAaron Patterson2014-10-131-0/+4
|
* Encapsulate knowledge of type objects on `ActiveRecord::Result`Sean Griffin2014-06-221-4/+40
| | | | | | | | | | | | | 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.
* Return sized enumerator from Batches#find_eachMarc-Andre Lafortune2014-02-051-0/+6
|
* Strengthen test with different nb of rows and columnsMarc-Andre Lafortune2014-02-051-2/+4
|
* Merge pull request #10993 from Empact/result-each-enumeratorCarlos Antonio da Silva2013-06-251-1/+0
| | | | Change Result#each to return an Enumerator when called without a block.
* Change Result#each to return an Enumerator when called without a block.Ben Woosley2013-06-181-0/+33
As with #10992, this lets us call #with_index, etc on the results.