About Me

I'm a software developer living in Vancouver, BC. I use:
  • Ruby on Rails
  • MySql
  • Javascript
Currently working at Noomii!

Counter caches in Rails, with conditions

08 April 2019 on

Recently I needed to update a counter cache to only count child elements meeting some criteria. In this case a User has many Reviews, but we only want to count the ‘approved’ reviews in our counter cache that we use for display. Rails comes with a nice counter cache implementation which is what we have been using thus far.

touch: true, dependent: :destroy, $!

09 February 2016 on rails

A little while ago our team was faced with an issue: certain DELETE requests were taking extremely long to process, to the tune of over 1 minute! This post explores what can happen when you have dependent: :destroy in a has_many relationship