From 667968fbb400ee90c207e769333174a044c9cfa4 Mon Sep 17 00:00:00 2001 From: Sam Goldstein Date: Wed, 17 Apr 2013 13:58:28 -0700 Subject: [PATCH] Fix N+1 for looping challenge --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/controllers/loop_controller.rb | 2 +- config/database.yml | 13 +++++++++++-- config/environments/production.rb | 2 +- config/newrelic.yml | 8 ++++---- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 22a6909..c5d5e46 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem 'nokogiri' gem 'httparty' gem 'dalli' -gem 'newrelic_rpm', '>=3.5' +gem 'newrelic_rpm', '>=3.6' gem "pg", ">= 0.14.1" group :production do diff --git a/Gemfile.lock b/Gemfile.lock index 6ee0904..f0f9424 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,7 +61,7 @@ GEM mime-types (1.21) multi_json (1.6.1) multi_xml (0.5.3) - newrelic_rpm (3.5.7.59) + newrelic_rpm (3.6.0.78) nokogiri (1.5.6) pg (0.14.1) polyglot (0.3.3) @@ -120,7 +120,7 @@ DEPENDENCIES dalli httparty jquery-rails - newrelic_rpm (>= 3.5) + newrelic_rpm (>= 3.6) nokogiri pg (>= 0.14.1) rails (= 3.2.12) diff --git a/app/controllers/loop_controller.rb b/app/controllers/loop_controller.rb index db17768..c27c029 100644 --- a/app/controllers/loop_controller.rb +++ b/app/controllers/loop_controller.rb @@ -1,5 +1,5 @@ class LoopController < ApplicationController def index - @sites = WebSite.limit(1000) + @sites = WebSite.includes(:icon).limit(1000) end end diff --git a/config/database.yml b/config/database.yml index 6d5407b..fed30ea 100644 --- a/config/database.yml +++ b/config/database.yml @@ -18,8 +18,17 @@ development: encoding: unicode database: newrelic-ruby-kata_development pool: 5 - username: <%= ENV['USER'] %> - password: + username: postgres + password: demo + template: template0 +production: + adapter: postgresql + host: localhost + encoding: unicode + database: newrelic-ruby-kata_development + pool: 5 + username: postgres + password: demo template: template0 # Connect on a TCP socket. Omitted by default since the client uses a diff --git a/config/environments/production.rb b/config/environments/production.rb index c92a516..f2e7657 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -9,7 +9,7 @@ config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_assets = true # Compress JavaScripts and CSS config.assets.compress = true diff --git a/config/newrelic.yml b/config/newrelic.yml index 6e22cda..1cb90fa 100644 --- a/config/newrelic.yml +++ b/config/newrelic.yml @@ -5,7 +5,7 @@ common: &default_settings # You must specify the license key associated with your New Relic # account. This key binds your Agent's data to your account in the # New Relic service. - license_key: '<%= ENV["NEW_RELIC_LICENSE_KEY"] %>' + license_key: 'bb2daacefc44283a2dcb3f233491f43c783aa8d1' # Agent Enabled (Rails Only) # Use this setting to force the agent to run or not run. @@ -32,7 +32,7 @@ common: &default_settings # - Ajax Service # - All Services # - app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> + app_name: Ruby Code Kata # When "true", the agent collects performance data about your # application and reports this data to the New Relic service at @@ -220,7 +220,7 @@ development: # 'enabled'). # NOTE: for initial evaluation purposes, you may want to temporarily # turn the agent on in development mode. - monitor_mode: false + monitor_mode: true # Rails Only - when running in Developer Mode, the New Relic Agent will # present performance information on the last 100 transactions you have @@ -252,4 +252,4 @@ production: staging: <<: *default_settings monitor_mode: true - app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Staging) \ No newline at end of file + app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Staging)