Skip to content

Commit bbc6998

Browse files
committed
database indexes!
1 parent 36ad7fa commit bbc6998

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

app/controllers/protips_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def spam
1313

1414
def show
1515
return (@protip = Protip.random.first) if params[:id] == 'random'
16-
@protip = Protip.find_by_public_id!(params[:id])
16+
@protip = Protip.where(public_id: params[:id]).includes(:comments).first
1717

1818
if params[:slug] != @protip.slug
1919
seo_url = slug_protips_url(id: @protip.public_id, slug: @protip.slug)

app/views/layouts/application.html.haml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
= render 'shared/analytics'
1111
%body
1212
.flex.flex-column{:style => "min-height:100vh"}
13-
%header.border-bottom
14-
-if Rails.env.production?
15-
.clearfix.center.py1.yellow.bg-navy
16-
%strong This is a preview release of the next Coderwall. Any changes made here will be lost.
13+
%header.border-bottom
1714
%nav.clearfix.px2
1815
.sm-col.py2
1916
%a.btn.logo{:href => root_url} Coderwall
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class ImprovingDatabasePerformane < ActiveRecord::Migration
2+
def change
3+
add_index "users", "username", unique: true
4+
add_index "protips", "public_id", unique: true
5+
add_index "protips", "score", unique: false
6+
add_index "comments", "protip_id", unique: false
7+
add_index "badges", "user_id", unique: false
8+
end
9+
end

db/schema.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20160214213211) do
14+
ActiveRecord::Schema.define(version: 20160219071138) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -28,6 +28,8 @@
2828
t.datetime "updated_at", null: false
2929
end
3030

31+
add_index "badges", ["user_id"], name: "index_badges_on_user_id", using: :btree
32+
3133
create_table "comments", force: :cascade do |t|
3234
t.text "body"
3335
t.integer "protip_id"
@@ -37,6 +39,8 @@
3739
t.integer "likes_count", default: 0
3840
end
3941

42+
add_index "comments", ["protip_id"], name: "index_comments_on_protip_id", using: :btree
43+
4044
create_table "likes", force: :cascade do |t|
4145
t.integer "likable_id"
4246
t.integer "user_id"
@@ -63,6 +67,8 @@
6367
t.boolean "flagged", default: false
6468
end
6569

70+
add_index "protips", ["public_id"], name: "index_protips_on_public_id", unique: true, using: :btree
71+
add_index "protips", ["score"], name: "index_protips_on_score", using: :btree
6672
add_index "protips", ["tags"], name: "index_protips_on_tags", using: :gin
6773

6874
create_table "users", force: :cascade do |t|
@@ -102,5 +108,6 @@
102108
add_index "users", ["email"], name: "index_users_on_email", using: :btree
103109
add_index "users", ["remember_token"], name: "index_users_on_remember_token", using: :btree
104110
add_index "users", ["skills"], name: "index_users_on_skills", using: :gin
111+
add_index "users", ["username"], name: "index_users_on_username", unique: true, using: :btree
105112

106113
end

0 commit comments

Comments
 (0)