Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is my lab #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,30 @@ To get started, create and migrate, then run `rake data:gen`. This will take ab

I suggest you start by optimizing the user page. Go to /users/5, look at the logs created by that, and bring it down to below 100ms. Right now the dashboard will take around 90 seconds, so save the dashboard for last.

You'll need to paginate some excessive queries also. I suggest using kaminari.
You'll need to paginate some excessive queries also. I suggest using kaminari.
>>>>>>> fd328a948f0e6f3363f15c84126b789b838143f1


# The Fastest Lab

#### Venue Show
(from views) | (from AR) | Total

initial 269.5ms 1636.0ms 1930ms
eager_loading 139.2ms 1503.6ms 1645ms

#### User Show
_attendance | show | (from views) | (from AR) | Total

initial 163.9ms 1652.6ms 134.8ms 2142.3ms 2280ms
eager loading 31.2ms 1259.6ms 47.1ms 1522.7ms 1669ms
add_idx:follows 30.5ms 218.6ms 47.0ms 482.4ms 593ms
add_2dx:follows 29.6ms 46.1m 45.7ms 338.7ms 445ms
add_idx:attends 30.4ms 44.2ms 45.6ms 30.4ms 133ms
fixed migrtions 29.2ms 36.7ms 37.2ms 16.0ms 70ms


#### Dashboard Show
_attendance | application | (from views) | (from AR) | Total

initial 290.9ms 292.5ms 256.6ms 81.7ms 409ms
4 changes: 2 additions & 2 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def show
@followed_attendances += a
end
@followed_attendances.sort_by!{|a| a.show.date}

end
end
end
end
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def create
redirect_to new_session_path
end
end

def show
@user = User.find(params[:id])
@user = User.includes(attendances: [show: :venue]).find(params[:id])
if signed_in?
@following = current_user.outward_follows.where(
:followed_id => @user.id).exists?
Expand All @@ -23,4 +23,4 @@ def show
def index
@users = User.all
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/venues_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class VenuesController < ApplicationController
def show
@venue = Venue.find(params[:id])
@venue = Venue.includes(:shows).find(params[:id])
end
def index
@venues = Venue.all
end
end
end
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class User < ActiveRecord::Base
has_secure_password

before_validation { |user| user.email = email.downcase }
before_save :create_remember_token

Expand All @@ -14,6 +14,7 @@ class User < ActiveRecord::Base

has_many :attendances


def avatar
a = read_attribute(:avatar)
unless a
Expand Down
6 changes: 3 additions & 3 deletions app/views/attendances/_attendance.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div>
<p>
<p class="_attendance">
<%= link_to attendance.show do %>
<%= attendance.show.title %>
on
<%= attendance.show.date.in_time_zone("Pacific Time (US & Canada)") %>
<% end %>
At:
At:
<%= link_to attendance.show.venue do %>
<%= attendance.show.venue.name %>
<% end %>
</p>
</div>
</div>
6 changes: 3 additions & 3 deletions app/views/attendances/_attendance_with_user.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<p>
<p class="_attendence_user">
<%= image_tag attendance.user.avatar, :class => 'avatar' %>
<%= link_to attendance.user do %>
<%= attendance.user.name %>
Expand All @@ -10,9 +10,9 @@
on
<%= attendance.show.date.in_time_zone("Pacific Time (US & Canada)") %>
<% end %>
At:
At:
<%= link_to attendance.show.venue do %>
<%= attendance.show.venue.name %>
<% end %>
</p>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</span>
<h2>
<p>
follows <%= @user.followeds.size %> users and is followed by
follows <%= @user.followeds.size %> users and is followed by
<%= @user.followers.size %> users.
</p>

Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20140318233227_add_2index_to_follows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Add2indexToFollows < ActiveRecord::Migration
def change
add_index :follows, :follower_id
add_index :follows, :followed_id
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140319000333_add_index_to_attendences.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIndexToAttendences < ActiveRecord::Migration
def change
add_index :attendances, :user_id
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140319004822_add_index_to_shows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIndexToShows < ActiveRecord::Migration
def change
add_index :shows, :user
end
end
7 changes: 6 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140317230057) do
ActiveRecord::Schema.define(version: 20140319000333) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -23,13 +23,18 @@
t.datetime "updated_at"
end

add_index "attendances", ["user_id"], name: "index_attendances_on_user_id", using: :btree

create_table "follows", force: true do |t|
t.integer "followed_id"
t.integer "follower_id"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "follows", ["followed_id"], name: "index_follows_on_followed_id", using: :btree
add_index "follows", ["follower_id"], name: "index_follows_on_follower_id", using: :btree

create_table "shows", force: true do |t|
t.integer "venue_id"
t.string "title"
Expand Down