Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jnewland/lazy_record
Proof of concept Lazy-Loading for ActiveRecord. Inspired by the 'kickers' of Ambition.
https://github.com/jnewland/lazy_record
Last synced: about 16 hours ago
JSON representation
Proof of concept Lazy-Loading for ActiveRecord. Inspired by the 'kickers' of Ambition.
- Host: GitHub
- URL: https://github.com/jnewland/lazy_record
- Owner: jnewland
- License: other
- Created: 2008-01-27T02:42:01.000Z (almost 17 years ago)
- Default Branch: master
- Last Pushed: 2008-03-26T19:09:46.000Z (over 16 years ago)
- Last Synced: 2023-04-10T15:07:05.305Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 88.9 KB
- Stars: 13
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: MIT-LICENSE
Awesome Lists containing this project
README
LazyRecord
==========Proof of concept Lazy-Loading for ActiveRecord. Inspired by the 'kickers' of Ambition.
>> b = Buzz.lazy_find(:first)
=> #>
-------------No SQL query is run until a method is called on this 'Promise'
>> b.to_s
-------------Buzz Load (0.000578) SELECT * FROM buzz LIMIT 1
=> "Inaugural Buzz"
Use the +lazy_record+ class method to make this the default for a certain class:
class Buzz << ActiveRecord::Base
lazy_record
end
>> b = Buzz.find(:first)
=> #>
-------------No SQL query is run until a method is called on this 'Promise'
>> b.to_s
-------------Buzz Load (0.000578) SELECT * FROM buzz LIMIT 1
=> "Inaugural Buzz"Why you might want to use this
===========Say you've got some kick-ass cache_fu going on in your views - huge blocks of HTML being cached with a TTL of 30 mins or so.
But, each hit on your controller still fires off the 'spensive DB queries to fetch your tag cloud. With lazy loading, these
queries aren't run until absolutely necessary - giving your DB a rest til your cache expires, and boosting your reqs/sec.Why you might not want to use this
===========>> b = Buzz.lazy_find(123023424)
=> #>
>> puts "booleans are screwed" if b
booleans are screwedPromise code from here: http://moonbase.rydia.net/software/lazy.rb/
Contact
=======
Jesse Newland
[email protected]