Skip to content

Commit

Permalink
UI to revert tag changes one-by-one (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meow authored Dec 30, 2023
1 parent 217621a commit 9b76673
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/philomena/workers/tag_change_revert_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/philomena_web/templates/ip_profile/show.html.slime
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b76673

Please sign in to comment.