Fix error when parsing updating feeds without item guids

This commit is contained in:
Shadowfacts 2022-09-19 10:02:11 -04:00
parent 6f3d18a1ba
commit ff3d9affe5
2 changed files with 11 additions and 4 deletions

View File

@ -12,7 +12,7 @@ defmodule Frenzy.Task.CreateItem do
def run(feed, entry) do
Logger.metadata(item_task_id: generate_task_id())
url = get_real_url(entry)
{guid, url} = real_guid_and_url(entry)
Logger.debug("Creating item for #{url}")
@ -29,8 +29,7 @@ defmodule Frenzy.Task.CreateItem do
end
item_params = %{
# fallback to url if guid isn't present
guid: entry.guid || url,
guid: guid,
title: entry.title,
url: url,
date: date,
@ -132,6 +131,12 @@ defmodule Frenzy.Task.CreateItem do
:ok
end
def real_guid_and_url(entry) do
url = get_real_url(entry)
# fallback to url if guid isn't present
{entry.guid || url, url}
end
defp get_real_url(entry) do
links = Enum.reject(entry.links, fn {_, rel} -> rel == "shorturl" end)

View File

@ -230,7 +230,9 @@ defmodule Frenzy.UpdateFeeds do
end
Enum.each(rss.items, fn entry ->
unless Item.exists?(feed.id, entry.guid) do
{guid, _} = CreateItem.real_guid_and_url(entry)
unless Item.exists?(feed.id, guid) do
CreateItem.start_link(feed, entry)
end
end)