Sort on and index taggings, ftw

This commit is contained in:
Raphael Sofaer 2011-07-07 15:14:29 -07:00
parent d0ce257107
commit e98cc4b960
3 changed files with 12 additions and 3 deletions

View file

@ -64,7 +64,7 @@ class TagsController < ApplicationController
max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
@posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time))
@posts = @posts.includes({:comments => {:author => :profile}}, :photos).order('posts.created_at DESC').limit(15)
@posts = @posts.includes({:comments => {:author => :profile}}, :photos).order('taggings.created_at DESC').limit(15)
else
@posts = []
end

View file

@ -0,0 +1,8 @@
class IndexTaggingsCreatedAt < ActiveRecord::Migration
def self.up
add_index :taggings, :created_at
end
def self.down
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110705003445) do
ActiveRecord::Schema.define(:version => 20110707221112) do
create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false
@ -343,6 +343,7 @@ ActiveRecord::Schema.define(:version => 20110705003445) do
t.datetime "created_at"
end
add_index "taggings", ["created_at"], :name => "index_taggings_on_created_at"
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
add_index "taggings", ["taggable_id", "taggable_type", "tag_id"], :name => "index_taggings_uniquely", :unique => true