Compare commits

..

No commits in common. "a02ec174beb9a2a1037e30c87f3a8b6a3fa69ea8" and "bf98614de9389d563e51f96e43f9cf7d399cf897" have entirely different histories.

4 changed files with 6 additions and 14 deletions

View File

@ -83,10 +83,5 @@ defmodule Frenzy.Item do
item item
|> cast(attrs, [:guid, :title, :url, :creator, :date, :content, :read, :read_date, :tombstone]) |> cast(attrs, [:guid, :title, :url, :creator, :date, :content, :read, :read_date, :tombstone])
|> validate_required([:guid, :url, :date, :content, :feed]) |> 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
end end

View File

@ -62,7 +62,7 @@ defmodule Frenzy.Task.CreateItem do
end end
case result do case result do
{:error, error} -> {:err, error} ->
Logger.error(error) Logger.error(error)
{:ok, item_params} -> {:ok, item_params} ->

View File

@ -53,6 +53,8 @@ defmodule Frenzy.UpdateFeeds do
Logger.info("Updating #{count} feeds") Logger.info("Updating #{count} feeds")
Enum.each(feeds, &update_feed/1)
Enum.each(feeds, fn feed -> Enum.each(feeds, fn feed ->
try do try do
update_feed(feed) update_feed(feed)
@ -158,9 +160,11 @@ defmodule Frenzy.UpdateFeeds do
FetchFavicon.run(feed) FetchFavicon.run(feed)
end end
feed = Repo.preload(feed, [:items])
Enum.each(rss.items, fn entry -> Enum.each(rss.items, fn entry ->
# todo: use Repo.exists for this # todo: use Repo.exists for this
unless Item.exists?(feed.id, entry.guid) do if !Enum.any?(feed.items, fn item -> item.guid == entry.guid end) do
CreateItem.start_link(feed, entry) CreateItem.start_link(feed, entry)
end end
end) end)

View File

@ -1,7 +0,0 @@
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