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:
parent
24038667b2
commit
8e3404a239
3 changed files with 32 additions and 4 deletions
|
|
@ -91,6 +91,13 @@ defmodule Pleroma.Instances.Instance do
|
|||
|
||||
def reachable?(url_or_host) when is_binary(url_or_host), do: true
|
||||
|
||||
@doc "Creates a record for the instance unless one exists. Existing records are kept."
|
||||
def ensure_exists(url_or_host) when is_binary(url_or_host) do
|
||||
%Instance{host: host(url_or_host)}
|
||||
|> changeset(%{})
|
||||
|> Repo.insert(on_conflict: :nothing, conflict_target: :host)
|
||||
end
|
||||
|
||||
def set_reachable(url_or_host) when is_binary(url_or_host) do
|
||||
host = host(url_or_host)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Filter
|
||||
alias Pleroma.Hashtag
|
||||
alias Pleroma.Instances.Instance
|
||||
alias Pleroma.Maps
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
|
|
@ -2068,10 +2069,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
else
|
||||
maybe_handle_clashing_nickname(data)
|
||||
|
||||
data
|
||||
|> User.remote_user_changeset()
|
||||
|> Repo.insert()
|
||||
|> User.set_cache()
|
||||
with {:ok, user} <- data |> User.remote_user_changeset() |> Repo.insert() do
|
||||
# Keeps the instances table complete, so it can list our peers.
|
||||
Instance.ensure_exists(user.ap_id)
|
||||
User.set_cache({:ok, user})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue