gallery reindexing to context

This commit is contained in:
byte[] 2020-12-12 16:51:11 -05:00
parent dd535b5af2
commit d567d5ffc0
2 changed files with 13 additions and 5 deletions

View file

@ -49,6 +49,7 @@ defmodule Philomena.Galleries do
%Gallery{}
|> Gallery.creation_changeset(attrs, user)
|> Repo.insert()
|> reindex_after_update()
end
@doc """
@ -67,6 +68,7 @@ defmodule Philomena.Galleries do
gallery
|> Gallery.changeset(attrs)
|> Repo.update()
|> reindex_after_update()
end
@doc """
@ -91,6 +93,7 @@ defmodule Philomena.Galleries do
Repo.delete(gallery)
|> case do
{:ok, gallery} ->
unindex_gallery(gallery)
Images.reindex_images(images)
{:ok, gallery}
@ -119,6 +122,16 @@ defmodule Philomena.Galleries do
Elasticsearch.update_by_query(Gallery, data.query, data.set_replacements, data.replacements)
end
defp reindex_after_update({:ok, gallery}) do
reindex_gallery(gallery)
{:ok, gallery}
end
defp reindex_after_update(error) do
error
end
def reindex_gallery(%Gallery{} = gallery) do
Exq.enqueue(Exq, "indexing", IndexWorker, ["Galleries", "id", [gallery.id]])

View file

@ -106,8 +106,6 @@ defmodule PhilomenaWeb.GalleryController do
case Galleries.create_gallery(user, gallery_params) do
{:ok, gallery} ->
Galleries.reindex_gallery(gallery)
conn
|> put_flash(:info, "Gallery successfully created.")
|> redirect(to: Routes.gallery_path(conn, :show, gallery))
@ -130,8 +128,6 @@ defmodule PhilomenaWeb.GalleryController do
case Galleries.update_gallery(gallery, gallery_params) do
{:ok, gallery} ->
Galleries.reindex_gallery(gallery)
conn
|> put_flash(:info, "Gallery successfully updated.")
|> redirect(to: Routes.gallery_path(conn, :show, gallery))
@ -146,7 +142,6 @@ defmodule PhilomenaWeb.GalleryController do
gallery = conn.assigns.gallery
{:ok, _gallery} = Galleries.delete_gallery(gallery)
Galleries.unindex_gallery(gallery)
conn
|> put_flash(:info, "Gallery successfully destroyed.")