diff --git a/lib/philomena/tags.ex b/lib/philomena/tags.ex index 4e115e73..e47046a1 100644 --- a/lib/philomena/tags.ex +++ b/lib/philomena/tags.ex @@ -256,9 +256,20 @@ defmodule Philomena.Tags do end def unalias_tag(%Tag{} = tag) do + former_alias = Repo.preload(tag, :aliased_tag).aliased_tag + tag |> Tag.unalias_changeset() |> Repo.update() + |> case do + {:ok, _} = result -> + reindex_tag_images(former_alias) + + result + + result -> + result + end end defp array_replace(queryable, column, old_value, new_value) do diff --git a/lib/philomena_web/controllers/tag/alias_controller.ex b/lib/philomena_web/controllers/tag/alias_controller.ex index 65ef5876..b4d8da60 100644 --- a/lib/philomena_web/controllers/tag/alias_controller.ex +++ b/lib/philomena_web/controllers/tag/alias_controller.ex @@ -29,10 +29,12 @@ defmodule PhilomenaWeb.Tag.AliasController do end def delete(conn, _params) do - {:ok, _tag} = Tags.unalias_tag(conn.assigns.tag) + spawn(fn -> + {:ok, _tag} = Tags.unalias_tag(conn.assigns.tag) + end) conn - |> put_flash(:info, "Tag alias removed.") + |> put_flash(:info, "Tag dealias queued.") |> redirect(to: Routes.tag_path(conn, :show, conn.assigns.tag)) end end