Compare commits
2 Commits
bf98614de9
...
a02ec174be
Author | SHA1 | Date |
---|---|---|
Shadowfacts | a02ec174be | |
Shadowfacts | cd36b40978 |
|
@ -83,5 +83,10 @@ defmodule Frenzy.Item do
|
|||
item
|
||||
|> cast(attrs, [:guid, :title, :url, :creator, :date, :content, :read, :read_date, :tombstone])
|
||||
|> validate_required([:guid, :url, :date, :content, :feed])
|
||||
|> unique_constraint(:items_feed_guid_index)
|
||||
end
|
||||
|
||||
def exists?(feed_id, guid) do
|
||||
Frenzy.Repo.exists?(__MODULE__, feed_id: feed_id, guid: guid)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -62,7 +62,7 @@ defmodule Frenzy.Task.CreateItem do
|
|||
end
|
||||
|
||||
case result do
|
||||
{:err, error} ->
|
||||
{:error, error} ->
|
||||
Logger.error(error)
|
||||
|
||||
{:ok, item_params} ->
|
||||
|
|
|
@ -53,8 +53,6 @@ defmodule Frenzy.UpdateFeeds do
|
|||
|
||||
Logger.info("Updating #{count} feeds")
|
||||
|
||||
Enum.each(feeds, &update_feed/1)
|
||||
|
||||
Enum.each(feeds, fn feed ->
|
||||
try do
|
||||
update_feed(feed)
|
||||
|
@ -160,11 +158,9 @@ defmodule Frenzy.UpdateFeeds do
|
|||
FetchFavicon.run(feed)
|
||||
end
|
||||
|
||||
feed = Repo.preload(feed, [:items])
|
||||
|
||||
Enum.each(rss.items, fn entry ->
|
||||
# todo: use Repo.exists for this
|
||||
if !Enum.any?(feed.items, fn item -> item.guid == entry.guid end) do
|
||||
unless Item.exists?(feed.id, entry.guid) do
|
||||
CreateItem.start_link(feed, entry)
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
defmodule Frenzy.Repo.Migrations.CreatItemUniqueIndex do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create unique_index(:items, [:feed_id, :guid], name: :items_feed_guid_index)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue