<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title>Andrew Avenoso - Blogs at Near Infinity</title>


        <link>http://www.nearinfinity.com/blogs/</link>
        <description>Employee Blogs</description>
        <language>en</language>
        <copyright>Copyright 2010</copyright>
        <lastBuildDate>Fri, 20 Apr 2007 13:26:00 -0500</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <item>
            <title>Rails edge finally supports Query Caching</title>
            <description><![CDATA[I just learned about a feature in Rails that I've been wanting for a long time.
In the past, if you were to run two identical database queries in a row, it would hit the database twice<br/>
<code class="prettyprint">
p = Person.find 1
p = Person.find 1
</code><br/><br/>
produces the following logging<br/>
<code class="prettyprint">
Person Load (0.010000)?[0m   ?[0;1mSELECT * FROM people WHERE (people.`id` = 1)
Person Load (0.010000)?[0m   ?[0;1mSELECT * FROM people WHERE (people.`id` = 1)
</code><br/><br/>

If you freeze to the Rails Edge the previous code will now produce this<br/>
<code class="prettyprint">
Person Load (0.010000)?[0m   ?[0;1mSELECT * FROM people WHERE (people.`id` = 1)
CACHE (0.000000)?[0m   ?[0mSELECT * FROM people WHERE (people.`id` = 1)
</code><br/><br/>
So the second call is being pulled from the cache and takes 0.000000 seconds to retrieve

By default this is available when running in a controller or .rhtml
<p>If you want to see this work on the console you can use the cache method </p>
<code class="prettyprint">
Person.cache do
&nbsp;&nbsp;p = Person.find 1
&nbsp;&nbsp;p = Person.find 1
end
</code><br/><br/>

This is by no means a replacement for memcache, but I like it because it increases performance without having to do any additional coding or configuration.
Another thing to remember is that the cache only lasts as long as the request, so you don't need to worry about stale data or cache expiration.

Now... Why would any programmer do a find for the same id multiple times in one request?
You probably won't, but ActiveRecord will.
If you have a highly denormalized database with many lookup tables, this can be a huge performance improvement.
Let's say you have 5 stores, 200 products and 5 product_types
<code class="prettyprint">
<br /><br />s = Store.find 1, :include=&gt;:products
s.products.each { |p| puts "#{p.name} is of type #{p.product_type.name}" }<br /><br /></code>
Doing a <code class="prettyprint">puts</code> is obviously a contrived example, but I often traverse model relationships like this in my views.

Before this feature, these two lines would have produced 201 database queries
Now with Query Caching this will be between 2 and 6 queries.

You might think that you could just add a <code class="prettyprint">:include =&gt; :product_type</code> in your product model.  This works while you're loading products, but not if you've already included products in store.  In other words, it appears that ActiveRecord can only do an <code class="prettyprint">:include</code> one level deep

This is a great way to keep from having to roll your own solution or monkey patch ActiveRecord, I look forward to this feature moving from edge to production.]]></description>
            <link>http://www.nearinfinity.com/blogs/andrew_avenoso/rails_edge_finally_supports_query.html</link>
            <guid>http://www.nearinfinity.com/blogs/andrew_avenoso/rails_edge_finally_supports_query.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">ActiveRecord</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">caching</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">database</category>
            
            <pubDate>Fri, 20 Apr 2007 13:26:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Browser settings across multiple computers</title>
            <description><![CDATA[One of the problems that I have with my computers is keeping the settings the same across all of them.  I have my desktop, laptop, and work computer and would like to keep things like my bookmarks the same across all of them.

I have been using <a href="http://del.icio.us">del.icio.us</a> to keep all my bookmarks and the <a href="http://www.mozilla.com/firefox/">firefox</a> live bookmark feature to access them on each computer.  While is is better than nothing, it leaves much to be desired.

I just ran into a tool from <a href="http://www.google.com">Google</a> that should make the whole process much better.  It's called <a href="http://www.google.com/tools/firefox/browsersync/">Google Browser Sync</a> and it seems to solve many of the issues.

This is a <a href="http://www.mozilla.com/firefox/">firefox</a> plugin that you install on each of your computers and it uses your google account to keep certain things synchronized between each of your computers.

At this time they support<ul><li>bookmarks - This is the main thing I wanted</li>
<li>history - Some people might find this useful</li>
<li>cookies - For all the bad rap that cookies get, this is a great feature for web sites that recognize you like <a href="http://www.amazon.com">Amazon</a></li>
<li>tabs - This is really cool. I could have tabs open on my home desktop, take my laptop to a internet cafe and open firefox to the same exact web site I was working on at home.</li>
<li>saved passwords - This one really scares me, Do we really trust google so blindly?  Sure, don't be evil, but...</li>
</ul>

This is a great start, what would be an incredible enhancement would be the ability to synchronize the installation of other plugins as well as the plugin configurations.  All <a href="http://www.mozilla.com/firefox/">firefox</a> users know that it's power comes from having lots of plugins installed.  It is difficult to have the same plugins installed and configured on all my instances of <a href="http://www.mozilla.com/firefox/">firefox</a>, so this would be a wonderful addition.]]></description>
            <link>http://www.nearinfinity.com/blogs/andrew_avenoso/browser_settings_across_multiple_computers.html</link>
            <guid>http://www.nearinfinity.com/blogs/andrew_avenoso/browser_settings_across_multiple_computers.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Thu, 22 Jun 2006 12:07:52 -0500</pubDate>
        </item>
        
    </channel>
</rss>
