UI to revert tag changes one-by-one (#202)

This commit is contained in:
Nighty 2023-12-30 17:32:49 +01:00 committed by GitHub
parent 217621a9e1
commit 9b766733a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 5 deletions

View file

@ -24,7 +24,10 @@ defmodule Philomena.TagChangeRevertWorker do
end
defp revert_all(queryable, attributes) do
Batch.query_batches(queryable, [batch_size: 100], fn queryable ->
batch_size = attributes["batch_size"] || 100
attributes = Map.delete(attributes, "batch_size")
Batch.query_batches(queryable, [batch_size: batch_size], fn queryable ->
ids = Repo.all(select(queryable, [tc], tc.id))
TagChanges.mass_revert(ids, cast_ip(atomify_keys(attributes)))
end)

View file

@ -7,15 +7,14 @@ defmodule PhilomenaWeb.TagChange.FullRevertController do
plug :verify_authorized
plug PhilomenaWeb.UserAttributionPlug
def create(conn, params) do
attributes = conn.assigns.attributes
def create(%{assigns: %{attributes: attributes}} = conn, params) do
attributes = %{
ip: to_string(attributes[:ip]),
fingerprint: attributes[:fingerprint],
referrer: attributes[:referrer],
user_agent: attributes[:referrer],
user_id: attributes[:user].id
user_id: attributes[:user].id,
batch_size: attributes[:batch_size] || 100
}
case params do

View file

@ -20,6 +20,7 @@ ul
h2 Actions
ul
li = link "Revert all tag changes", to: Routes.tag_change_full_revert_path(@conn, :create, [fingerprint: @fingerprint]), data: [confirm: "Are you really, really sure?", method: "create"]
li = link "...the button above didn't work (use carefully, this is resource-intensive)", to: Routes.tag_change_full_revert_path(@conn, :create, [fingerprint: @fingerprint, batch_size: 1]), data: [confirm: "Please confirm that you're aware that this may crash the site and are ready to take on the full wrath of the admins if it does so after you press this button.", method: "create"]
h4 Observed users
table.table

View file

@ -20,6 +20,7 @@ ul
h2 Actions
ul
li = link "Revert all tag changes", to: Routes.tag_change_full_revert_path(@conn, :create, [ip: to_string(@ip)]), data: [confirm: "Are you really, really sure?", method: "create"]
li = link "...the button above didn't work (use carefully, this is resource-intensive)", to: Routes.tag_change_full_revert_path(@conn, :create, [ip: to_string(@ip), batch_size: 1]), data: [confirm: "Please confirm that you're aware that this may crash the site and are ready to take on the full wrath of the admins if it does so after you press this button.", method: "create"]
h4 Observed users
table.table