When you have a table with serialized columns active record will always treat them as dirty. It can create unnecessary overhead when just incrementing a simple counter.

Fortunately rails has a method that just update the counter and nothing else.

apidock: update_counters

If you have a Movie model with a counter named like_count and you would like to increment it by one you would use the following method.

1
Movie.update_counters id, :like_count => 1

As a bonus you also get a locking

Posted in Programming, Rails at May 19th, 2012. No Comments
Tagged with , , . Written by:

If you are on OSX you can learn Capistrano to talk. And when you do, he can tell you when your deploy is done.

Just add the following task to your deploy.rb

1
2
3
task :do_speak do
  system("/usr/bin/say -r 250 -v Zarvox 'Sir, your #{rails_env} deploy is done'")
end

And hook it up to run after deploy

1
after 'deploy', 'do_speak'

Now use your imagination, and add more words to Capistrano’s vocabulary :)

If you are using Linux or windows you can use espeak to get the same results

Cheers!

Posted in Programming, Rails, Ruby at May 19th, 2012. No Comments
Tagged with , , . Written by:

It's past my bedtime is using WP-Gravatar