Coder Social home page Coder Social logo

active-record-instance-count's Introduction

ActiveRecordInstanceCount

Rack middleware to log the number of instantiated ActiveRecord models in a request. Helpful to see how many objects you're instantiating. First step to recognize you have a problem.

Logs a message like (notice the last line):

Started GET "/wines/7016/pricing" for 192.168.255.9 at 2012-08-07 06:26:00 +0000
Processing by WineBookPricingController#index as HTML
  Parameters: {"wine_book_id"=>"7016"}
  Rendered wine_book_pricing/index.html.haml within layouts/application (9.7ms)
  Rendered shared/_analytics.html.erb (0.0ms)
  Rendered shared/_ajax_status.html.haml (0.1ms)
  Rendered shared/_navbar.html.haml (1.8ms)
  Rendered shared/_alerts.html.haml (0.4ms)
Completed 200 OK in 71ms (Views: 35.7ms | ActiveRecord: 21.5ms)
Instantiation Breakdown: Total: 7 | WineBook: 4 | User: 1 | Group: 1 | Producer: 1

Installation

Add to your Gemfile:

gem 'active-record-instance-count'

Then provide an initializer, like config/initializers/active_record_instance_counter.rb:

YourApp::Application.middleware.use( ActiveRecordInstanceCount::Middleware, :logger => Rails.logger )

Provide a different Logger instance if you would like to redirect the output somewhere else. But keep in mind that no more context will be provided (e.g. the request details) so it might be fairly useless.

Credits

Heavily inspired from Oink

active-record-instance-count's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

01022012

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.