remove N+1 queries on current user outfits page
This commit is contained in:
parent
5e89287537
commit
4a69772cd2
8 changed files with 21 additions and 4 deletions
4
Gemfile
4
Gemfile
|
@ -48,6 +48,10 @@ gem "carrierwave", "~> 0.5.8"
|
||||||
|
|
||||||
gem "parallel", "~> 0.5.17"
|
gem "parallel", "~> 0.5.17"
|
||||||
|
|
||||||
|
group :development do
|
||||||
|
gem "bullet", "~> 4.1.5"
|
||||||
|
end
|
||||||
|
|
||||||
group :development_async do
|
group :development_async do
|
||||||
# async wrappers
|
# async wrappers
|
||||||
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
|
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
|
||||||
|
|
|
@ -86,6 +86,8 @@ GEM
|
||||||
arel (2.0.10)
|
arel (2.0.10)
|
||||||
bcrypt-ruby (2.1.4)
|
bcrypt-ruby (2.1.4)
|
||||||
builder (2.1.2)
|
builder (2.1.2)
|
||||||
|
bullet (4.1.5)
|
||||||
|
uniform_notifier (~> 1.0.0)
|
||||||
carrierwave (0.5.8)
|
carrierwave (0.5.8)
|
||||||
activesupport (~> 3.0)
|
activesupport (~> 3.0)
|
||||||
character-encodings (0.4.1)
|
character-encodings (0.4.1)
|
||||||
|
@ -218,6 +220,7 @@ GEM
|
||||||
polyglot
|
polyglot
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
tzinfo (0.3.31)
|
tzinfo (0.3.31)
|
||||||
|
uniform_notifier (1.0.2)
|
||||||
vegas (0.1.8)
|
vegas (0.1.8)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
warden (1.0.6)
|
warden (1.0.6)
|
||||||
|
@ -235,6 +238,7 @@ PLATFORMS
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
RocketAMF!
|
RocketAMF!
|
||||||
addressable
|
addressable
|
||||||
|
bullet (~> 4.1.5)
|
||||||
carrierwave (~> 0.5.8)
|
carrierwave (~> 0.5.8)
|
||||||
character-encodings (~> 0.4.1)
|
character-encodings (~> 0.4.1)
|
||||||
compass (~> 0.10.1)
|
compass (~> 0.10.1)
|
||||||
|
|
|
@ -12,7 +12,9 @@ class OutfitsController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if user_signed_in?
|
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|
|
respond_to do |format|
|
||||||
format.html { render }
|
format.html { render }
|
||||||
format.json { render :json => @outfits }
|
format.json { render :json => @outfits }
|
||||||
|
|
|
@ -13,7 +13,7 @@ module OutfitsHelper
|
||||||
outfit = outfit_or_options
|
outfit = outfit_or_options
|
||||||
end
|
end
|
||||||
query = outfit.to_query
|
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
|
link_to content, wardrobe_path(:anchor => query), options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,12 @@ class Outfit < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_query
|
def to_query
|
||||||
|
ids = self.worn_and_unworn_item_ids
|
||||||
|
|
||||||
{
|
{
|
||||||
:closet => closet_item_ids,
|
:closet => ids[:worn] + ids[:unworn],
|
||||||
:color => color_id,
|
:color => color_id,
|
||||||
:objects => worn_item_ids,
|
:objects => ids[:worn],
|
||||||
:species => species_id,
|
:species => species_id,
|
||||||
:state => pet_state_id
|
:state => pet_state_id
|
||||||
}.to_query
|
}.to_query
|
||||||
|
|
5
config/initializers/bullet.rb
Normal file
5
config/initializers/bullet.rb
Normal 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
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
BIN
vendor/cache/uniform_notifier-1.0.2.gem
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue