Search code examples
ruby-on-railsdatabasepostgresqlherokuimpressions

Rails Impressionist making expensive queries


I'm using charlotte-ruby/impressionist to track impressions within my rails app.

I have a very simple implementation, similar to what's shown in the quick start guide. Effectively: - Controller: impressionist actions: [:show, :index] - View: @post.impressionist_count - Model: is_impressionable

I ran into some DB queuing issues today, and found the following when checking out my expensive queries within Heroku Postgres: enter image description here

I immediately removed impressionist from my controllers/views (at 14:30), and you can see how it impacted performance: enter image description here

Has anyone run into a similar issue with the impressionist gem? Any ideas of why it's so expensive from a DB perspective?

EDIT:

Here are the indexes that were added:

  add_index "impressions", ["controller_name", "action_name", "ip_address"], name: "controlleraction_ip_index", using: :btree
  add_index "impressions", ["controller_name", "action_name", "request_hash"], name: "controlleraction_request_index", using: :btree
  add_index "impressions", ["controller_name", "action_name", "session_hash"], name: "controlleraction_session_index", using: :btree
  add_index "impressions", ["impressionable_type", "impressionable_id", "ip_address"], name: "poly_ip_index", using: :btree
  add_index "impressions", ["impressionable_type", "impressionable_id", "request_hash"], name: "poly_request_index", using: :btree
  add_index "impressions", ["impressionable_type", "impressionable_id", "session_hash"], name: "poly_session_index", using: :btree
  add_index "impressions", ["impressionable_type", "message", "impressionable_id"], name: "impressionable_type_message_index", using: :btree
  add_index "impressions", ["user_id"], name: "index_impressions_on_user_id", using: :btree

Solution

  • @Ken Hampson - thanks for the recommendation. Looking for the long running SELECT queries identified yet another index that was needed. Once added, POOF, all was better. Very odd that this issue just showed up after having the site live for a few months. Impressions must have hit a size that broke the camel's back. Appreciate the help!

    For anyone that runs into similar issues with degrading performance due to DB queries (on Heroku), going to https://postgres.heroku.com/databases/your-database-name and looking at the "Expensive Queries" table is a great way to figure out where you may have missed an index.