ActiveRecord extension for finding ids or column values more efficiently than through the default finders.
User.find_column_values('email') User.find_set_ids User.find_multiple_column_values('id', 'email') # returns an array of hashes with ids and emails
find_ids accepts all the normal ActiveRecord finder conditions.
Some benchmarks against a fairly "wide" table with 100 records, 10,000 times each. YMMV based on your particular circumstances, although find_ids should always be faster than instantiating records. Benchmark script included, and it's super easy to just test on your own app.
user system total real find(:all).map 26.460000 3.130000 29.590000 ( 72.656614) find(:all, :select).map 12.770000 0.560000 13.330000 ( 16.232474) find_ids 7.870000 0.340000 8.210000 ( 10.465719)
Installation for Rails
script/plugin install git://github.com/stopdropandrew/find_ids.git
- Let me know here: Issue Tracking
- January 28, 2010: First public release 0.1/
Copyright (C) 2010 Andrew Grim / The Shredders at Kongregate
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.