Make feed refresh request asynchronous

This commit is contained in:
Shadowfacts 2020-05-31 16:13:00 -04:00
parent c37bed932f
commit b63081392c
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 4 additions and 5 deletions

View File

@ -10,7 +10,7 @@ defmodule Frenzy.UpdateFeeds do
end end
def refresh(pid, feed) do def refresh(pid, feed) do
GenServer.call(pid, {:refresh, feed}) GenServer.cast(pid, {:refresh, feed})
end end
def init(state) do def init(state) do
@ -19,10 +19,9 @@ defmodule Frenzy.UpdateFeeds do
{:ok, state} {:ok, state}
end end
def handle_call({:refresh, feed}, _from, state) do def handle_cast({:refresh, feed}, state) do
update_feed(feed) update_feed(feed)
new_feed = Feed |> Repo.get(feed.id) |> Repo.preload(:items) {:noreply, state}
{:reply, new_feed, state}
end end
def handle_info(:update_feeds, state) do def handle_info(:update_feeds, state) do

View File

@ -110,7 +110,7 @@ defmodule FrenzyWeb.FeedController do
def refresh(conn, _params) do def refresh(conn, _params) do
feed = conn.assigns[:feed] feed = conn.assigns[:feed]
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed) Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
conn conn
|> put_flash(:info, "Refreshing feed. Wait a moment before reloading...") |> put_flash(:info, "Refreshing feed. Wait a moment before reloading...")