简体   繁体   中英

Rails 3: Feed is taking too long

I have a twitter-like feed in my web app. I've tried to optimize the query as much as possible but it still freezes when it's loading the "tweets" from PostgresSQL database.

Twitter, github, facebook, feeds are so smooth and fast.

What's the best way to accomplish that?

Regards.

**Edit: the code is the one in 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
#

Sorry for not providing enough information.**

您在表上放置了任何索引吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM