remove N+1 queries on current user outfits page

This commit is contained in:
Emi Matchu 2012-08-09 18:32:33 -04:00
parent 5e89287537
commit 4a69772cd2
8 changed files with 21 additions and 4 deletions

View file

@ -48,6 +48,10 @@ gem "carrierwave", "~> 0.5.8"
gem "parallel", "~> 0.5.17"
group :development do
gem "bullet", "~> 4.1.5"
end
group :development_async do
# async wrappers
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'

View file

@ -86,6 +86,8 @@ GEM
arel (2.0.10)
bcrypt-ruby (2.1.4)
builder (2.1.2)
bullet (4.1.5)
uniform_notifier (~> 1.0.0)
carrierwave (0.5.8)
activesupport (~> 3.0)
character-encodings (0.4.1)
@ -218,6 +220,7 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
uniform_notifier (1.0.2)
vegas (0.1.8)
rack (>= 1.0.0)
warden (1.0.6)
@ -235,6 +238,7 @@ PLATFORMS
DEPENDENCIES
RocketAMF!
addressable
bullet (~> 4.1.5)
carrierwave (~> 0.5.8)
character-encodings (~> 0.4.1)
compass (~> 0.10.1)

View file

@ -12,7 +12,9 @@ class OutfitsController < ApplicationController
def index
if user_signed_in?
@outfits = current_user.outfits.wardrobe_order
@outfits = current_user.outfits.
includes(:item_outfit_relationships, {:pet_state => :pet_type}).
wardrobe_order
respond_to do |format|
format.html { render }
format.json { render :json => @outfits }

View file

@ -13,7 +13,7 @@ module OutfitsHelper
outfit = outfit_or_options
end
query = outfit.to_query
query << "&outfit=#{outfit.id}" if user_signed_in? && outfit.user == current_user
query << "&outfit=#{outfit.id}" if user_signed_in? && outfit.user_id == current_user.id
link_to content, wardrobe_path(:anchor => query), options
end

View file

@ -44,10 +44,12 @@ class Outfit < ActiveRecord::Base
end
def to_query
ids = self.worn_and_unworn_item_ids
{
:closet => closet_item_ids,
:closet => ids[:worn] + ids[:unworn],
:color => color_id,
:objects => worn_item_ids,
:objects => ids[:worn],
:species => species_id,
:state => pet_state_id
}.to_query

View file

@ -0,0 +1,5 @@
if Rails.env.development?
Bullet.enable = true
Bullet.alert = true
Bullet.rails_logger = true
end

BIN
vendor/cache/bullet-4.1.5.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/uniform_notifier-1.0.2.gem vendored Normal file

Binary file not shown.