diff --git a/services/federation_impl.py b/services/federation_impl.py index 9ae761a..6574dbe 100644 --- a/services/federation_impl.py +++ b/services/federation_impl.py @@ -286,6 +286,23 @@ class SqlFederationService: if actor is None: raise ValueError(f"Actor not found: {username}") + # Upsert: update if already following, insert if new + existing = ( + await session.execute( + select(APFollower).where( + APFollower.actor_profile_id == actor.id, + APFollower.follower_acct == follower_acct, + ) + ) + ).scalar_one_or_none() + + if existing: + existing.follower_inbox = follower_inbox + existing.follower_actor_url = follower_actor_url + existing.follower_public_key = follower_public_key + await session.flush() + return _follower_to_dto(existing) + follower = APFollower( actor_profile_id=actor.id, follower_acct=follower_acct,