diff options
author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2020-07-07 12:07:30 +0200 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2020-07-08 06:28:40 +0200 |
commit | 8c9df2d2e6a5a3639f6b411cd3e9b57248a0650c (patch) | |
tree | 27fd35fb4e4c82bf997b770ab14189cb0b621e79 /lib/pleroma/instances | |
parent | 013e2c505786dff311bcc8bf23631d6a1a1636ef (diff) | |
download | pleroma-8c9df2d2e6a5a3639f6b411cd3e9b57248a0650c.tar.gz |
instance: Prevent loop of updates
Diffstat (limited to 'lib/pleroma/instances')
-rw-r--r-- | lib/pleroma/instances/instance.ex | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index b97e229e5..a1f935232 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -127,30 +127,23 @@ defmodule Pleroma.Instances.Instance do existing_record = Repo.get_by(Instance, %{host: host}) now = NaiveDateTime.utc_now() - if existing_record && existing_record.favicon && + if existing_record && existing_record.favicon_updated_at && NaiveDateTime.diff(now, existing_record.favicon_updated_at) < 86_400 do existing_record.favicon else favicon = scrape_favicon(instance_uri) - cond do - is_binary(favicon) && existing_record -> - existing_record - |> changeset(%{favicon: favicon, favicon_updated_at: now}) - |> Repo.update() - - favicon - - is_binary(favicon) -> - %Instance{} - |> changeset(%{host: host, favicon: favicon, favicon_updated_at: now}) - |> Repo.insert() - - favicon - - true -> - nil + if existing_record do + existing_record + |> changeset(%{favicon: favicon, favicon_updated_at: now}) + |> Repo.update() + else + %Instance{} + |> changeset(%{host: host, favicon: favicon, favicon_updated_at: now}) + |> Repo.insert() end + + favicon end end |