feat(instances): record the instance of new remote users

The instances table only got rows from fetches, reachability changes
and favicon lookups, so most hosts we know users from had none. Insert
a row when a remote user is created, keeping existing rows.
This commit is contained in:
Lain Soykaf 2026-10-27 20:48:02 +04:00
commit 8e3404a239
No known key found for this signature in database
3 changed files with 32 additions and 4 deletions

View file

@ -184,6 +184,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert user.follower_address == "http://mastodon.example.org/users/admin/followers"
end
test "it records the user's instance" do
refute Repo.get_by(Pleroma.Instances.Instance, host: "mastodon.example.org")
{:ok, _user} = ActivityPub.make_user_from_ap_id("http://mastodon.example.org/users/admin")
assert %{unreachable_since: nil} =
Repo.get_by(Pleroma.Instances.Instance, host: "mastodon.example.org")
end
test "it keeps an existing instance record" do
unreachable_since = ~N[2020-01-01 00:00:00.000000]
insert(:instance, host: "mastodon.example.org", unreachable_since: unreachable_since)
{:ok, _user} = ActivityPub.make_user_from_ap_id("http://mastodon.example.org/users/admin")
assert %{unreachable_since: ^unreachable_since} =
Repo.get_by(Pleroma.Instances.Instance, host: "mastodon.example.org")
end
test "it returns a user that is invisible" do
user_id = "http://mastodon.example.org/users/relay"
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)