ModelObserver

A rails plugin to count the model object creations between each request, and help to find out the duplication.

Build Status Gem Version Code Climate Coverage Status

Installation

Add to your Gemfile

group :development do
  gem 'model_observer'
end

and bundle

bundle

Query Log

The time include instantiate models will be logged after each sql log like this:

Author Load (0.5ms)  SELECT `authors`.* FROM `authors` WHERE `authors`.`id` = 1 LIMIT 1
Author Instantiate (1.5ms)  SELECT `authors`.* FROM `authors` WHERE `authors`.`id` = 1 LIMIT 1

1.5ms == 0.5ms(DB query) + 1.0ms(model instantiation)

Summary Log

The summary of each request will be added to the end like this:

===== Model Observer Start =====
Author: 1 sum(10.6ms) avg(10.6ms)
Book: 27 sum(25.7ms) avg(1.0ms)
  id(319): 3
  id(377): 3
  id(487): 3
  id(489): 3
  id(493): 3
  id(496): 3
  id(499): 3
  id(507): 3
  id(536): 3
===== Model Observer End =======