aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/tweet.rb
diff options
context:
space:
mode:
authorRhenium <rhenium@rhe.jp>2013-11-16 23:48:52 +0900
committerRhenium <rhenium@rhe.jp>2013-11-16 23:48:52 +0900
commit298d783c9bcd44b4bc96c37ce46fb1ad57c97d59 (patch)
treea266dcdc76719c35d6b9b221643603d3308a4411 /app/models/tweet.rb
parent205a4152b02efd73e17c9f79521782c02d85f7c9 (diff)
downloadaclog-298d783c9bcd44b4bc96c37ce46fb1ad57c97d59.tar.gz
speed up discovered_by
Diffstat (limited to 'app/models/tweet.rb')
-rw-r--r--app/models/tweet.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb
index ba5e0c8..c573176 100644
--- a/app/models/tweet.rb
+++ b/app/models/tweet.rb
@@ -21,11 +21,9 @@ class Tweet < ActiveRecord::Base
scope :favorited_by, -> user { joins(:favorites).where(favorites: {user: user}) }
scope :retweeted_by, -> user { joins(:retweets).where(retweets: {user: user}) }
scope :discovered_by, -> user {
- un = "SELECT favorites.tweet_id FROM favorites WHERE favorites.user_id = #{user.id}" +
- " UNION " +
- "SELECT retweets.tweet_id FROM retweets WHERE retweets.user_id = #{user.id}"
+ un = [:favorites, :retweets].map {|m| user.__send__(m).select(:tweet_id).order(tweet_id: :desc).limit(all.limit_value.to_i + all.offset_value.to_i).to_sql }.join(") UNION (")
- joins("INNER JOIN (#{un}) m ON m.tweet_id = tweets.id")
+ joins("INNER JOIN ((#{un})) reactions ON reactions.tweet_id = tweets.id")
}
def notify_favorite