You are correct, update_all is called once for each faq item, which results in a separate query for each faq item. The performance gain is because update_all updates the order field in a single query as opposed to first loading the model then doing an update in a separate query.
This still works in Rails 4 by the way, but the syntax is a little different:
FYI, If you're trying this in your own app and not seeing the etag headers, it could be because MiniProfiler (described in episode #368) strips the etag headers and rewrites the cache-control header. See my comment in that episode: http://railscasts.com/episodes/368-miniprofiler?view=comments#comment_159804
I was trying the caching techniques from episode #321 and pulling my hair out trying to figure out why I wasn't get etag headers in my responses. Turns out that MiniProfiler strips the etag headers. It also rewrites the Cache-Control header.
From MiniProfiler source: mini-profiler/profiler.rb
ruby
# mini profiler is meddling with stuff, we can not cache cause we will get incorrect data# Rack::ETag has already inserted some nonesense in the chain
headers.delete('ETag')
headers.delete('Date')
headers['Cache-Control'] = 'must-revalidate, private, max-age=0'
[status, headers, body]
Probably isn't a big deal because the profiler is disabled in production. But makes things trickier on the development side. Just wanted to share this in case anyone hits the same issue.
You are correct, update_all is called once for each faq item, which results in a separate query for each faq item. The performance gain is because update_all updates the order field in a single query as opposed to first loading the model then doing an update in a separate query.
This still works in Rails 4 by the way, but the syntax is a little different:
FYI, If you're trying this in your own app and not seeing the etag headers, it could be because MiniProfiler (described in episode #368) strips the etag headers and rewrites the cache-control header. See my comment in that episode: http://railscasts.com/episodes/368-miniprofiler?view=comments#comment_159804
I was trying the caching techniques from episode #321 and pulling my hair out trying to figure out why I wasn't get etag headers in my responses. Turns out that MiniProfiler strips the etag headers. It also rewrites the Cache-Control header.
From MiniProfiler source: mini-profiler/profiler.rb
Probably isn't a big deal because the profiler is disabled in production. But makes things trickier on the development side. Just wanted to share this in case anyone hits the same issue.
In case it helps anyone else, here is a jQuery version of endless_page.js The jQuery version fixes the compatibility problem with IE as well.