Fix followers synchronization for local numeric AP ID followers
Some checks are pending
Chromatic / Run Chromatic (push) Waiting to run

This commit is contained in:
Claire 2025-09-25 15:58:56 +02:00
parent 7dfbcbafc1
commit ce0d389811
2 changed files with 18 additions and 3 deletions

View File

@ -215,9 +215,8 @@ module Account::Interactions
def local_followers_hash
Rails.cache.fetch("followers_hash:#{id}:local") do
digest = "\x00" * 32
# TODO
followers.where(domain: nil).pluck_each('false as numeric_ap_id', :id, :username) do |numeric_ap_id, id, username|
uri = numeric_ap_id ? ActivityPub::TagManager.instance.uri_for_account_id(id) : ActivityPub::TagManager.instance.uri_for_username(username)
followers.where(domain: nil).pluck_each(:id_scheme, :id, :username) do |id_scheme, id, username|
uri = id_scheme == 'numeric_ap_id' ? ActivityPub::TagManager.instance.uri_for_account_id(id) : ActivityPub::TagManager.instance.uri_for_username(username)
Xorcist.xor!(digest, Digest::SHA256.digest(uri))
end
digest.unpack1('H*')

View File

@ -563,6 +563,22 @@ RSpec.describe Account::Interactions do
me.follow!(remote_alice)
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
end
context 'when using numeric ID based scheme' do
let(:me) { Fabricate(:account, username: 'Me', id_scheme: :numeric_ap_id) }
it 'returns correct hash for local users' do
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
end
it 'invalidates cache as needed when removing or adding followers' do
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
me.unfollow!(remote_alice)
expect(remote_alice.local_followers_hash).to eq '0000000000000000000000000000000000000000000000000000000000000000'
me.follow!(remote_alice)
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
end
end
end
describe 'muting an account' do