diff options
author | lain <lain@soykaf.club> | 2023-12-07 04:20:54 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2023-12-07 04:20:54 +0000 |
commit | 6c10fd22a3c0b80335d1b1eda8440e2241fa0226 (patch) | |
tree | e21df9165a2eb2d7a278f819553168aa9ad551f0 /lib | |
parent | 6a6a631c814ff946358dd386bd41bda2c8a37111 (diff) | |
parent | 1ad0d94d6f1f11c848f277877cc14b3a47a7ae95 (diff) | |
download | pleroma-6c10fd22a3c0b80335d1b1eda8440e2241fa0226.tar.gz pleroma-6c10fd22a3c0b80335d1b1eda8440e2241fa0226.zip |
Merge branch 'reachable-upsert' into 'develop'
Change set_reachable/1 to an upsert
See merge request pleroma/pleroma!3986
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/instances/instance.ex | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index 9756c66dc..101e5dc88 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -97,13 +97,9 @@ defmodule Pleroma.Instances.Instance do def reachable?(url_or_host) when is_binary(url_or_host), do: true def set_reachable(url_or_host) when is_binary(url_or_host) do - with host <- host(url_or_host), - %Instance{} = existing_record <- Repo.get_by(Instance, %{host: host}) do - {:ok, _instance} = - existing_record - |> changeset(%{unreachable_since: nil}) - |> Repo.update() - end + %Instance{host: host(url_or_host)} + |> changeset(%{unreachable_since: nil}) + |> Repo.insert(on_conflict: {:replace, [:unreachable_since]}, conflict_target: :host) end def set_reachable(_), do: {:error, nil} |