mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
add reindex and delete buttons
This commit is contained in:
parent
a28d233751
commit
70b077e4e7
6 changed files with 61 additions and 39 deletions
|
@ -163,7 +163,9 @@ defmodule Philomena.Tags do
|
||||||
|> select([i, _t], i.id)
|
|> select([i, _t], i.id)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
{:ok, _tag} = Repo.delete(tag)
|
{:ok, tag} = Repo.delete(tag)
|
||||||
|
|
||||||
|
Tag.delete_document(tag.id)
|
||||||
|
|
||||||
Image
|
Image
|
||||||
|> where([i], i.id in ^image_ids)
|
|> where([i], i.id in ^image_ids)
|
||||||
|
@ -205,25 +207,32 @@ defmodule Philomena.Tags do
|
||||||
|> where(tag_id: ^tag.id)
|
|> where(tag_id: ^tag.id)
|
||||||
|> Repo.update_all(set: [tag_id: target_tag.id])
|
|> Repo.update_all(set: [tag_id: target_tag.id])
|
||||||
|
|
||||||
# Update counters
|
# Update counter
|
||||||
new_count =
|
|
||||||
Image
|
|
||||||
|> join(:inner, [i], _ in assoc(i, :tags))
|
|
||||||
|> where([i, t], i.hidden_from_users == false and t.id == ^target_tag.id)
|
|
||||||
|> Repo.aggregate(:count, :id)
|
|
||||||
|
|
||||||
Tag
|
|
||||||
|> where(id: ^target_tag.id)
|
|
||||||
|> Repo.update_all(set: [images_count: new_count])
|
|
||||||
|
|
||||||
Tag
|
Tag
|
||||||
|> where(id: ^tag.id)
|
|> where(id: ^tag.id)
|
||||||
|> Repo.update_all(set: [images_count: 0, aliased_tag_id: target_tag.id, updated_at: DateTime.utc_now()])
|
|> Repo.update_all(set: [images_count: 0, aliased_tag_id: target_tag.id, updated_at: DateTime.utc_now()])
|
||||||
|
|
||||||
# Finally, update images
|
# Finally, reindex
|
||||||
|
reindex_tag_images(target_tag)
|
||||||
|
reindex_tags([tag, target_tag])
|
||||||
|
end
|
||||||
|
|
||||||
|
def reindex_tag_images(%Tag{} = tag) do
|
||||||
|
# First recount the tag
|
||||||
|
image_count =
|
||||||
|
Image
|
||||||
|
|> join(:inner, [i], _ in assoc(i, :tags))
|
||||||
|
|> where([i, t], i.hidden_from_users == false and t.id == ^tag.id)
|
||||||
|
|> Repo.aggregate(:count, :id)
|
||||||
|
|
||||||
|
Tag
|
||||||
|
|> where(id: ^tag.id)
|
||||||
|
|> Repo.update_all(set: [images_count: image_count])
|
||||||
|
|
||||||
|
# Then reindex
|
||||||
Image
|
Image
|
||||||
|> join(:inner, [i], _ in assoc(i, :tags))
|
|> join(:inner, [i], _ in assoc(i, :tags))
|
||||||
|> where([_i, t], t.id == ^target_tag.id)
|
|> where([_i, t], t.id == ^tag.id)
|
||||||
|> preload(^Images.indexing_preloads())
|
|> preload(^Images.indexing_preloads())
|
||||||
|> Image.reindex()
|
|> Image.reindex()
|
||||||
end
|
end
|
||||||
|
|
19
lib/philomena_web/controllers/tag/reindex_controller.ex
Normal file
19
lib/philomena_web/controllers/tag/reindex_controller.ex
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
defmodule PhilomenaWeb.Tag.ReindexController do
|
||||||
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
|
alias Philomena.Tags.Tag
|
||||||
|
alias Philomena.Tags
|
||||||
|
|
||||||
|
plug PhilomenaWeb.CanaryMapPlug, create: :alias
|
||||||
|
plug :load_and_authorize_resource, model: Tag, id_name: "tag_id", id_field: "slug", preload: [:implied_tags, :aliased_tag], persisted: true
|
||||||
|
|
||||||
|
def create(conn, _params) do
|
||||||
|
spawn fn ->
|
||||||
|
Tags.reindex_tag_images(conn.assigns.tag)
|
||||||
|
end
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Tag reindex started.")
|
||||||
|
|> redirect(to: Routes.tag_path(conn, :edit, conn.assigns.tag))
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ defmodule PhilomenaWeb.TagController do
|
||||||
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
|
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
|
||||||
plug PhilomenaWeb.CanaryMapPlug, update: :edit
|
plug PhilomenaWeb.CanaryMapPlug, update: :edit
|
||||||
plug :load_and_authorize_resource, model: Tag, id_field: "slug", only: [:show, :edit, :update, :delete], preload: [:aliases, :aliased_tag, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user]
|
plug :load_and_authorize_resource, model: Tag, id_field: "slug", only: [:show, :edit, :update, :delete], preload: [:aliases, :aliased_tag, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user]
|
||||||
plug :redirect_alias when action in [:show, :edit, :update, :delete]
|
plug :redirect_alias when action in [:show]
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
query_string = params["tq"] || "*"
|
query_string = params["tq"] || "*"
|
||||||
|
|
|
@ -232,6 +232,7 @@ defmodule PhilomenaWeb.Router do
|
||||||
resources "/tags", TagController, only: [:edit, :update, :delete] do
|
resources "/tags", TagController, only: [:edit, :update, :delete] do
|
||||||
resources "/image", Tag.ImageController, only: [:edit, :update, :delete], singleton: true
|
resources "/image", Tag.ImageController, only: [:edit, :update, :delete], singleton: true
|
||||||
resources "/alias", Tag.AliasController, only: [:edit, :update, :delete], singleton: true
|
resources "/alias", Tag.AliasController, only: [:edit, :update, :delete], singleton: true
|
||||||
|
resources "/reindex", Tag.ReindexController, only: [:create], singleton: true
|
||||||
end
|
end
|
||||||
|
|
||||||
resources "/pages", PageController, only: [:index, :new, :create, :edit, :update]
|
resources "/pages", PageController, only: [:index, :new, :create, :edit, :update]
|
||||||
|
|
|
@ -15,7 +15,7 @@ h1
|
||||||
=> submit "Alias tag", class: "button"
|
=> submit "Alias tag", class: "button"
|
||||||
|
|
||||||
br
|
br
|
||||||
= button_to "Remove tag alias", Routes.tag_alias_path(@conn, :delete, @tag), method: "delete", class: "button", data: [confirm: "Are you really, really sure?"]
|
= button_to "Remove tag alias", Routes.tag_alias_path(@conn, :delete, @tag), method: "delete", class: "button", data: [confirm: "Are you really, really sure?", disable_with: raw("Saving…")]
|
||||||
|
|
||||||
br
|
br
|
||||||
= link "Back", to: Routes.tag_path(@conn, :show, @tag)
|
= link "Back", to: Routes.tag_path(@conn, :show, @tag)
|
||||||
|
|
|
@ -36,26 +36,19 @@ p = link "Edit aliases", to: Routes.tag_alias_path(@conn, :edit, @tag)
|
||||||
br
|
br
|
||||||
= submit "Save Tag", class: "button button--state-primary"
|
= submit "Save Tag", class: "button button--state-primary"
|
||||||
|
|
||||||
/ not ready yet
|
br
|
||||||
br
|
br
|
||||||
br
|
input.toggle-box#tag-management checked="false" type="checkbox"
|
||||||
input.toggle-box#tag-management checked="false" type="checkbox"
|
label for="tag-management" Tag Processing
|
||||||
label for="tag-management" Tag Processing
|
.toggle-box-container
|
||||||
.toggle-box-container
|
.toggle-box-container__content
|
||||||
.toggle-box-container__content
|
= button_to "Rebuild index", Routes.tag_reindex_path(@conn, :create, @tag), method: "post", class: "button", data: [confirm: "Are you really, really sure?", disable_with: raw("Reindexing…")]
|
||||||
= link_to "Rebuild index", admin_tag_reindex_path(@tag), class: "button", data: { confirm: t("are_you_sure") }, method: :post
|
p Use this if the tag displays the wrong number of images or returns the wrong search results.
|
||||||
p Use this if the tag displays the wrong number of images or returns the wrong search results.
|
|
||||||
= link_to "Recreate slug", admin_tag_slug_path(@tag), class: "button", method: :post
|
= button_to "Destroy tag", Routes.tag_path(@conn, :delete, @tag), method: "delete", class: "button button--state-danger", data: [confirm: "Are you really, really sure?", disable_with: raw("Deleting…")]
|
||||||
p
|
p
|
||||||
| Use this for old tags with invalid slugs (
|
strong Irreversible. Use with extreme caution!
|
||||||
code
|
ul
|
||||||
' /mlp/ →
|
li Intended use is removing garbage tags.
|
||||||
= Tag.generate_slug "/mlp/"
|
li Will remove tag changes on the tag, but not on images or profiles.
|
||||||
| )
|
li Will unset the alias if this tag is an alias target, and will automatically remove any implications that exist to it.
|
||||||
= link_to "Destroy tag", admin_tag_path(@tag), class: "button button--state-danger", data: { confirm: t("are_you_sure") }, method: :delete
|
|
||||||
p
|
|
||||||
strong Irreversible. Use with extreme caution!
|
|
||||||
ul
|
|
||||||
li Intended use is removing garbage tags.
|
|
||||||
li Will remove tag changes on the tag, but not on images or profiles.
|
|
||||||
li Will fail if the tag is the target of an alias, is implied by other tags, or is a rating tag.
|
|
||||||
|
|
Loading…
Reference in a new issue