Rails Tips – Counter Cache (.size vs .count)

* Size (rails function) is more intelligent than count (ruby function) * Notice that when you counter cache, size makes only one call to db as opposed to count which does 2 queries. 1.9.2-p320 :057 > ParentModel.find(5765).childmodel.count RequestedTrip Load (0.3ms) SELECT `parent_models`.* FROM `parent_models` WHERE (`parent_models`.`id` = 5765) ORDER BY parent_models.created_at desc LIMIT 1 SQL […]

Continue reading