0.0
No commit activity in last 3 years
No release in over 3 years
A rails plugin to count the model object creations between each request, and help to find out the duplication.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

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

Configuration

Initialize ModelObserver at config/environments/development.rb with the following code:

config.after_initialize do
  ModelObserver.summary = true
  ModelObserver.instantiation_log = true
end

Summary Log

The summary of each request will be appended 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 =======

id(319): 3 means the models with same class(Book) and same id(319) have been instantiated three times.

Instantiation Log

The duration include query and 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)