Remove unfollowed hashtag posts from home feed (#26028)
parent
2d1ecbe1fe
commit
e8631f8e90
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TagUnmergeWorker
|
||||
include Sidekiq::Worker
|
||||
include DatabaseHelper
|
||||
|
||||
sidekiq_options queue: 'pull'
|
||||
|
||||
def perform(from_tag_id, into_account_id)
|
||||
with_primary do
|
||||
@from_tag = Tag.find(from_tag_id)
|
||||
@into_account = Account.find(into_account_id)
|
||||
end
|
||||
|
||||
with_read_replica do
|
||||
FeedManager.instance.unmerge_tag_from_home(@from_tag, @into_account)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
end
|
@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe TagUnmergeWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
describe 'perform' do
|
||||
let(:follower) { Fabricate(:account) }
|
||||
let(:followed) { Fabricate(:account) }
|
||||
let(:followed_tag) { Fabricate(:tag) }
|
||||
let(:unchanged_followed_tag) { Fabricate(:tag) }
|
||||
let(:status_from_followed) { Fabricate(:status, created_at: 2.hours.ago, account: followed) }
|
||||
let(:tagged_status) { Fabricate(:status, created_at: 1.hour.ago) }
|
||||
let(:unchanged_tagged_status) { Fabricate(:status) }
|
||||
|
||||
before do
|
||||
tagged_status.tags << followed_tag
|
||||
unchanged_tagged_status.tags << followed_tag
|
||||
unchanged_tagged_status.tags << unchanged_followed_tag
|
||||
|
||||
tag_follow = TagFollow.create_with(rate_limit: false).find_or_create_by!(tag: followed_tag, account: follower)
|
||||
TagFollow.create_with(rate_limit: false).find_or_create_by!(tag: unchanged_followed_tag, account: follower)
|
||||
|
||||
FeedManager.instance.push_to_home(follower, status_from_followed, update: false)
|
||||
FeedManager.instance.push_to_home(follower, tagged_status, update: false)
|
||||
FeedManager.instance.push_to_home(follower, unchanged_tagged_status, update: false)
|
||||
|
||||
tag_follow.destroy!
|
||||
end
|
||||
|
||||
it 'removes the expected status from the feed' do
|
||||
expect { subject.perform(followed_tag.id, follower.id) }
|
||||
.to change { HomeFeed.new(follower).get(10).pluck(:id) }
|
||||
.from([unchanged_tagged_status.id, tagged_status.id, status_from_followed.id])
|
||||
.to([unchanged_tagged_status.id, status_from_followed.id])
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue