about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-08 02:08:32 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-08 02:08:32 +0100
commitbb4d1eb2e86ec6227c18df29ce0f0f25ae2f6ee3 (patch)
treee0230cf6dc1913631aa333cc1b0724dfcc9863aa
parent096bfbad966e7dbd0ea2d71b12d1f411daabdb72 (diff)
Improve feed regeneration
-rw-r--r--app/lib/feed_manager.rb4
-rw-r--r--app/models/feed.rb3
-rw-r--r--app/services/fan_out_on_write_service.rb2
-rw-r--r--app/services/precompute_feed_service.rb10
-rw-r--r--app/workers/regeneration_worker.rb7
5 files changed, 15 insertions, 11 deletions
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 6a4f0edd6..af7b2380e 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -76,8 +76,8 @@ class FeedManager
   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
diff --git a/app/models/feed.rb b/app/models/feed.rb
index 211d64638..e7a39f5da 100644
--- a/app/models/feed.rb
+++ b/app/models/feed.rb
@@ -11,7 +11,8 @@ class Feed
 
     # 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
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 674665592..4f8777a50 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -33,7 +33,7 @@ class FanOutOnWriteService < BaseService
 
     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
diff --git a/app/services/precompute_feed_service.rb b/app/services/precompute_feed_service.rb
index eb5f48575..3094c50fd 100644
--- a/app/services/precompute_feed_service.rb
+++ b/app/services/precompute_feed_service.rb
@@ -2,17 +2,13 @@ class PrecomputeFeedService < BaseService
   # 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
diff --git a/app/workers/regeneration_worker.rb b/app/workers/regeneration_worker.rb
new file mode 100644
index 000000000..f0ed01d71
--- /dev/null
+++ b/app/workers/regeneration_worker.rb
@@ -0,0 +1,7 @@
+class RegenerationWorker
+  include Sidekiq::Worker
+
+  def perform(account_id, timeline_type)
+    PrecomputeFeedService.new.call(timeline_type, Account.find(account_id))
+  end
+end