mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-23 04:55:08 +01:00
Overwrite old statuses with reblogs in PrecomputeFeedService (#3984)
This commit is contained in:
parent
fb421a1f46
commit
7d8e3721ae
@ -14,7 +14,7 @@ class PrecomputeFeedService < BaseService
|
|||||||
|
|
||||||
def populate_feed
|
def populate_feed
|
||||||
redis.pipelined do
|
redis.pipelined do
|
||||||
statuses.each do |status|
|
statuses.reverse_each do |status|
|
||||||
process_status(status)
|
process_status(status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,13 +8,13 @@ RSpec.describe Feed, type: :model do
|
|||||||
Fabricate(:status, account: account, id: 2)
|
Fabricate(:status, account: account, id: 2)
|
||||||
Fabricate(:status, account: account, id: 3)
|
Fabricate(:status, account: account, id: 3)
|
||||||
Fabricate(:status, account: account, id: 10)
|
Fabricate(:status, account: account, id: 10)
|
||||||
redis = double(zrevrangebyscore: [['val2', 2.0], ['val1', 1.0], ['val3', 3.0], ['deleted', 4.0]], exists: false)
|
Redis.current.zadd(FeedManager.instance.key(:home, account.id),
|
||||||
allow(Redis).to receive(:current).and_return(redis)
|
[[4, 'deleted'], [3, 'val3'], [2, 'val2'], [1, 'val1']])
|
||||||
|
|
||||||
feed = Feed.new(:home, account)
|
feed = Feed.new(:home, account)
|
||||||
results = feed.get(3)
|
results = feed.get(3)
|
||||||
|
|
||||||
expect(results.map(&:id)).to eq [2, 1, 3]
|
expect(results.map(&:id)).to eq [3, 2]
|
||||||
expect(results.first.attributes.keys).to eq %w(id updated_at)
|
expect(results.first.attributes.keys).to eq %w(id updated_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,6 +13,7 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
|||||||
|
|
||||||
ActiveRecord::Migration.maintain_test_schema!
|
ActiveRecord::Migration.maintain_test_schema!
|
||||||
WebMock.disable_net_connect!
|
WebMock.disable_net_connect!
|
||||||
|
Redis.current = Redis::Namespace.new("mastodon_test#{ENV['TEST_ENV_NUMBER']}", redis: Redis.current)
|
||||||
Sidekiq::Testing.inline!
|
Sidekiq::Testing.inline!
|
||||||
Sidekiq::Logging.logger = nil
|
Sidekiq::Logging.logger = nil
|
||||||
|
|
||||||
@ -43,6 +44,11 @@ RSpec.configure do |config|
|
|||||||
https = ENV['LOCAL_HTTPS'] == 'true'
|
https = ENV['LOCAL_HTTPS'] == 'true'
|
||||||
Capybara.app_host = "http#{https ? 's' : ''}://#{ENV.fetch('LOCAL_DOMAIN')}"
|
Capybara.app_host = "http#{https ? 's' : ''}://#{ENV.fetch('LOCAL_DOMAIN')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.after :each do
|
||||||
|
keys = Redis.current.keys
|
||||||
|
Redis.current.del(keys) if keys.any?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec::Sidekiq.configure do |config|
|
RSpec::Sidekiq.configure do |config|
|
||||||
|
@ -11,12 +11,12 @@ RSpec.describe PrecomputeFeedService do
|
|||||||
account = Fabricate(:account)
|
account = Fabricate(:account)
|
||||||
followed_account = Fabricate(:account)
|
followed_account = Fabricate(:account)
|
||||||
Fabricate(:follow, account: account, target_account: followed_account)
|
Fabricate(:follow, account: account, target_account: followed_account)
|
||||||
status = Fabricate(:status, account: followed_account)
|
reblog = Fabricate(:status, account: followed_account)
|
||||||
|
status = Fabricate(:status, account: account, reblog: reblog)
|
||||||
expected_redis_args = FeedManager.instance.key(:home, account.id), status.id, status.id
|
|
||||||
expect_any_instance_of(Redis).to receive(:zadd).with(*expected_redis_args)
|
|
||||||
|
|
||||||
subject.call(account)
|
subject.call(account)
|
||||||
|
|
||||||
|
expect(Redis.current.zscore(FeedManager.instance.key(:home, account.id), reblog.id)).to eq status.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,10 +7,13 @@ describe Scheduler::FeedCleanupScheduler do
|
|||||||
let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
|
let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
|
||||||
|
|
||||||
it 'clears feeds of inactives' do
|
it 'clears feeds of inactives' do
|
||||||
expect_any_instance_of(Redis).to receive(:del).with(feed_key_for(inactive_user))
|
Redis.current.zadd(feed_key_for(inactive_user), 1, 1)
|
||||||
expect_any_instance_of(Redis).not_to receive(:del).with(feed_key_for(active_user))
|
Redis.current.zadd(feed_key_for(active_user), 1, 1)
|
||||||
|
|
||||||
subject.perform
|
subject.perform
|
||||||
|
|
||||||
|
expect(Redis.current.zcard(feed_key_for(inactive_user))).to eq 0
|
||||||
|
expect(Redis.current.zcard(feed_key_for(active_user))).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def feed_key_for(user)
|
def feed_key_for(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user