diff options
Diffstat (limited to 'app/models/tweet.rb')
-rw-r--r-- | app/models/tweet.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 3dc7ccd..9f769d2 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -26,6 +26,18 @@ class Tweet < ActiveRecord::Base scope :favorited_by, ->(user) { joins(:favorites).where(favorites: { user: user }) } + # deprecated + scope :discovered_by, ->(user) { + load_count = all.limit_value.to_i + all.offset_value.to_i + load_count = nil if load_count == 0 + + un = [:favorites, :retweets].map {|m| + user.__send__(m).select(:tweet_id).order(tweet_id: :desc).limit(load_count) + }.map {|m| "(#{m.to_sql})" }.join(" UNION ") + + joins("INNER JOIN ((#{un})) reactions ON reactions.tweet_id = tweets.id") + } + class << self def initialize_from_json(json, ignore_relation: false) tweet = self.new(id: json[:id], |