]> cat aescling's git repositories - mastodon.git/commitdiff
Store home feeds for 7 days instead of 14 (#7354)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 4 May 2018 22:54:24 +0000 (00:54 +0200)
committerGitHub <noreply@github.com>
Fri, 4 May 2018 22:54:24 +0000 (00:54 +0200)
* Store home feeds for 7 days instead of 14

Reduces workload for status fan-out to active followers

* Fix test for user model

app/models/user.rb
app/services/fan_out_on_write_service.rb
spec/models/user_spec.rb

index a9f3e1da267eabf2c0177ddcd42500dbe7f0b8b9..f5f542f07d6f07780f6a225f82b92670d39e4efd 100644 (file)
@@ -41,7 +41,7 @@ class User < ApplicationRecord
   include Settings::Extend
   include Omniauthable
 
-  ACTIVE_DURATION = 14.days
+  ACTIVE_DURATION = 7.days
 
   devise :two_factor_authenticatable,
          otp_secret_encryption_key: Rails.configuration.x.otp_secret
index 510b80c823a6629c417716c2edefb191439bfe8f..cb82a79ed339d2fcc9b5c4993089cf6a45dd731c 100644 (file)
@@ -37,7 +37,7 @@ class FanOutOnWriteService < BaseService
   def deliver_to_followers(status)
     Rails.logger.debug "Delivering status #{status.id} to followers"
 
-    status.account.followers.where(domain: nil).joins(:user).where('users.current_sign_in_at > ?', 14.days.ago).select(:id).reorder(nil).find_in_batches do |followers|
+    status.account.followers.where(domain: nil).joins(:user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).select(:id).reorder(nil).find_in_batches do |followers|
       FeedInsertWorker.push_bulk(followers) do |follower|
         [status.id, follower.id, :home]
       end
@@ -47,7 +47,7 @@ class FanOutOnWriteService < BaseService
   def deliver_to_lists(status)
     Rails.logger.debug "Delivering status #{status.id} to lists"
 
-    status.account.lists.joins(account: :user).where('users.current_sign_in_at > ?', 14.days.ago).select(:id).reorder(nil).find_in_batches do |lists|
+    status.account.lists.joins(account: :user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).select(:id).reorder(nil).find_in_batches do |lists|
       FeedInsertWorker.push_bulk(lists) do |list|
         [status.id, list.id, :list]
       end
index 760214dedecc7c871b6befe46d5e131c5cf374c1..cc8d88cc85b76724554c61be9c44da33a9d180cd 100644 (file)
@@ -75,7 +75,7 @@ RSpec.describe User, type: :model do
     describe 'inactive' do
       it 'returns a relation of inactive users' do
         specified = Fabricate(:user, current_sign_in_at: 15.days.ago)
-        Fabricate(:user, current_sign_in_at: 13.days.ago)
+        Fabricate(:user, current_sign_in_at: 6.days.ago)
 
         expect(User.inactive).to match_array([specified])
       end