forked from AkkomaGang/akkoma
instance: Prevent loop of updates
This commit is contained in:
parent
013e2c5057
commit
8c9df2d2e6
1 changed files with 11 additions and 18 deletions
|
@ -127,30 +127,23 @@ def get_or_update_favicon(%URI{host: host} = instance_uri) do
|
||||||
existing_record = Repo.get_by(Instance, %{host: host})
|
existing_record = Repo.get_by(Instance, %{host: host})
|
||||||
now = NaiveDateTime.utc_now()
|
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
|
NaiveDateTime.diff(now, existing_record.favicon_updated_at) < 86_400 do
|
||||||
existing_record.favicon
|
existing_record.favicon
|
||||||
else
|
else
|
||||||
favicon = scrape_favicon(instance_uri)
|
favicon = scrape_favicon(instance_uri)
|
||||||
|
|
||||||
cond do
|
if existing_record do
|
||||||
is_binary(favicon) && existing_record ->
|
existing_record
|
||||||
existing_record
|
|> changeset(%{favicon: favicon, favicon_updated_at: now})
|
||||||
|> changeset(%{favicon: favicon, favicon_updated_at: now})
|
|> Repo.update()
|
||||||
|> Repo.update()
|
else
|
||||||
|
%Instance{}
|
||||||
favicon
|
|> changeset(%{host: host, favicon: favicon, favicon_updated_at: now})
|
||||||
|
|> Repo.insert()
|
||||||
is_binary(favicon) ->
|
|
||||||
%Instance{}
|
|
||||||
|> changeset(%{host: host, favicon: favicon, favicon_updated_at: now})
|
|
||||||
|> Repo.insert()
|
|
||||||
|
|
||||||
favicon
|
|
||||||
|
|
||||||
true ->
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
favicon
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue