end
def filter_from_mentions?(status, receiver)
- should_filter = false
- should_filter = receiver.blocking?(status.account) # Filter if it's from someone I blocked
+ should_filter = receiver.id == status.account_id # Filter if I'm mentioning myself
+ should_filter = should_filter || receiver.blocking?(status.account) # or it's from someone I blocked
should_filter
end
end
# If we're after most recent items and none are there, we need to precompute the feed
if unhydrated.empty? && max_id == '+inf' && since_id == '-inf'
- PrecomputeFeedService.new.call(@type, @account, limit)
+ RegenerationWorker.perform_async(@account.id, @type)
+ Status.send("as_#{@type}_timeline", @account).paginate_by_max_id(limit, nil, nil)
else
status_map = Status.where(id: unhydrated).with_includes.with_counters.map { |status| [status.id, status] }.to_h
unhydrated.map { |id| status_map[id] }.compact
status.mentions.includes(:account).each do |mention|
mentioned_account = mention.account
- next if !mentioned_account.local? || mentioned_account.id == status.account_id || FeedManager.instance.filter?(:mentions, status, mentioned_account)
+ next if !mentioned_account.local? || FeedManager.instance.filter?(:mentions, status, mentioned_account)
FeedManager.instance.push(:mentions, mentioned_account, status)
end
end
# Fill up a user's home/mentions feed from DB and return a subset
# @param [Symbol] type :home or :mentions
# @param [Account] account
- # @return [Array]
- def call(type, account, limit)
+ def call(type, account)
instant_return = []
- Status.send("as_#{type}_timeline", account).order('id desc').limit(FeedManager::MAX_ITEMS).find_each do |status|
+ Status.send("as_#{type}_timeline", account).limit(FeedManager::MAX_ITEMS).each do |status|
next if FeedManager.instance.filter?(type, status, account)
- redis.zadd(FeedManager.instance.key(type, account.id), status.id, status.id)
- instant_return << status unless instant_return.size > limit
+ redis.zadd(FeedManager.instance.key(type, account.id), status.id, status.reblog? ? status.reblog_of_id : status.id)
end
-
- instant_return
end
private
--- /dev/null
+class RegenerationWorker
+ include Sidekiq::Worker
+
+ def perform(account_id, timeline_type)
+ PrecomputeFeedService.new.call(timeline_type, Account.find(account_id))
+ end
+end