Rails 3:饲料需要太长时间

时间:2010-12-15 20:33:12

标签: ruby-on-rails ruby database ruby-on-rails-3

我的网络应用中有类似Twitter的Feed。我试图尽可能地优化查询,但是当它从PostgresSQL数据库加载“推文”时它仍然会冻结。

Twitter,github,facebook,feed非常流畅和快速。

实现这一目标的最佳方法是什么?

问候。

**编辑:代码是railstutorial.org中的代码。 http://railstutorial.org/chapters/following-users#sec:scopes_subselects_and_a_lambda

# Return microposts from the users being followed by the given user.
  scope :from_users_followed_by, lambda { |user| followed_by(user) }

  private

    # Return an SQL condition for users followed by the given user.
    # We include the user's own id as well.
    def self.followed_by(user)
      followed_ids = user.following.map(&:id).join(", ")
      where("user_id IN (#{followed_ids}) OR user_id = :user_id",
            { :user_id => user })
    end


# Table name: microposts
#
#  id         :integer         not null, primary key
#  content    :string(255)
#  user_id    :integer
#  created_at :datetime
#  updated_at :datetime
#

很抱歉没有提供足够的信息。**

1 个答案:

答案 0 :(得分:0)

你在桌子上放了任何索引吗?