Remove spawn calls (#80)

This commit is contained in:
liamwhite 2020-12-06 11:42:14 -05:00 committed by GitHub
parent 7f348ff5b5
commit 6ebf080826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 399 additions and 249 deletions

View file

@ -20,7 +20,7 @@ config :elastix,
json_codec: Jason json_codec: Jason
config :exq, config :exq,
max_retries: 2, max_retries: 5,
scheduler_enable: true, scheduler_enable: true,
start_on_application: false start_on_application: false

View file

@ -55,7 +55,12 @@ config :philomena,
config :exq, config :exq,
host: System.get_env("REDIS_HOST", "localhost"), host: System.get_env("REDIS_HOST", "localhost"),
queues: [{"videos", 2}, {"images", 4}, {"indexing", 16}] queues: [
{"videos", 2},
{"images", 4},
{"indexing", 12},
{"notifications", 2}
]
if is_nil(System.get_env("START_WORKER")) do if is_nil(System.get_env("START_WORKER")) do
# Make queueing available but don't process any jobs # Make queueing available but don't process any jobs

View file

@ -11,9 +11,11 @@ defmodule Philomena.Comments do
alias Philomena.Reports.Report alias Philomena.Reports.Report
alias Philomena.Comments.Comment alias Philomena.Comments.Comment
alias Philomena.Comments.ElasticsearchIndex, as: CommentIndex alias Philomena.Comments.ElasticsearchIndex, as: CommentIndex
alias Philomena.IndexWorker
alias Philomena.Images.Image alias Philomena.Images.Image
alias Philomena.Images alias Philomena.Images
alias Philomena.Notifications alias Philomena.Notifications
alias Philomena.NotificationWorker
alias Philomena.Versions alias Philomena.Versions
alias Philomena.Reports alias Philomena.Reports
@ -64,7 +66,12 @@ defmodule Philomena.Comments do
end end
def notify_comment(comment) do def notify_comment(comment) do
spawn(fn -> Exq.enqueue(Exq, "notifications", NotificationWorker, ["Comments", comment.id])
end
def perform_notify(comment_id) do
comment = get_comment!(comment_id)
image = image =
comment comment
|> Repo.preload(:image) |> Repo.preload(:image)
@ -86,9 +93,6 @@ defmodule Philomena.Comments do
action: "commented on" action: "commented on"
} }
) )
end)
comment
end end
@doc """ @doc """
@ -216,24 +220,13 @@ defmodule Philomena.Comments do
end end
def reindex_comment(%Comment{} = comment) do def reindex_comment(%Comment{} = comment) do
spawn(fn -> Exq.enqueue(Exq, "indexing", IndexWorker, ["Comments", "id", [comment.id]])
Comment
|> preload(^indexing_preloads())
|> where(id: ^comment.id)
|> Repo.one()
|> Elasticsearch.index_document(Comment)
end)
comment comment
end end
def reindex_comments(image) do def reindex_comments(image) do
spawn(fn -> Exq.enqueue(Exq, "indexing", IndexWorker, ["Comments", "image_id", [image.id]])
Comment
|> preload(^indexing_preloads())
|> where(image_id: ^image.id)
|> Elasticsearch.reindex(Comment)
end)
image image
end end
@ -241,4 +234,11 @@ defmodule Philomena.Comments do
def indexing_preloads do def indexing_preloads do
[:user, image: :tags] [:user, image: :tags]
end end
def perform_reindex(column, condition) do
Comment
|> preload(^indexing_preloads())
|> where([c], field(c, ^column) in ^condition)
|> Elasticsearch.reindex(Comment)
end
end end

View file

@ -11,7 +11,10 @@ defmodule Philomena.Galleries do
alias Philomena.Galleries.Gallery alias Philomena.Galleries.Gallery
alias Philomena.Galleries.Interaction alias Philomena.Galleries.Interaction
alias Philomena.Galleries.ElasticsearchIndex, as: GalleryIndex alias Philomena.Galleries.ElasticsearchIndex, as: GalleryIndex
alias Philomena.IndexWorker
alias Philomena.GalleryReorderWorker
alias Philomena.Notifications alias Philomena.Notifications
alias Philomena.NotificationWorker
alias Philomena.Images alias Philomena.Images
@doc """ @doc """
@ -117,21 +120,13 @@ defmodule Philomena.Galleries do
end end
def reindex_gallery(%Gallery{} = gallery) do def reindex_gallery(%Gallery{} = gallery) do
spawn(fn -> Exq.enqueue(Exq, "indexing", IndexWorker, ["Galleries", "id", [gallery.id]])
Gallery
|> preload(^indexing_preloads())
|> where(id: ^gallery.id)
|> Repo.one()
|> Elasticsearch.index_document(Gallery)
end)
gallery gallery
end end
def unindex_gallery(%Gallery{} = gallery) do def unindex_gallery(%Gallery{} = gallery) do
spawn(fn ->
Elasticsearch.delete_document(gallery.id, Gallery) Elasticsearch.delete_document(gallery.id, Gallery)
end)
gallery gallery
end end
@ -140,6 +135,13 @@ defmodule Philomena.Galleries do
[:subscribers, :creator, :interactions] [:subscribers, :creator, :interactions]
end end
def perform_reindex(column, condition) do
Gallery
|> preload(^indexing_preloads())
|> where([g], field(g, ^column) in ^condition)
|> Elasticsearch.reindex(Gallery)
end
def add_image_to_gallery(gallery, image) do def add_image_to_gallery(gallery, image) do
Multi.new() Multi.new()
|> Multi.run(:lock, fn repo, %{} -> |> Multi.run(:lock, fn repo, %{} ->
@ -231,7 +233,12 @@ defmodule Philomena.Galleries do
end end
def notify_gallery(gallery) do def notify_gallery(gallery) do
spawn(fn -> Exq.enqueue(Exq, "notifications", NotificationWorker, ["Galleries", gallery.id])
end
def perform_notify(gallery_id) do
gallery = get_gallery!(gallery_id)
subscriptions = subscriptions =
gallery gallery
|> Repo.preload(:subscriptions) |> Repo.preload(:subscriptions)
@ -248,13 +255,15 @@ defmodule Philomena.Galleries do
action: "added images to" action: "added images to"
} }
) )
end)
gallery
end end
def reorder_gallery(gallery, image_ids) do def reorder_gallery(gallery, image_ids) do
spawn(fn -> Exq.enqueue(Exq, "indexing", GalleryReorderWorker, [gallery.id, image_ids])
end
def perform_reorder(gallery_id, image_ids) do
gallery = get_gallery!(gallery_id)
interactions = interactions =
Interaction Interaction
|> where([gi], gi.image_id in ^image_ids and gi.gallery_id == ^gallery.id) |> where([gi], gi.image_id in ^image_ids and gi.gallery_id == ^gallery.id)
@ -314,9 +323,6 @@ defmodule Philomena.Galleries do
# Now update all the associated images # Now update all the associated images
Images.reindex_images(Map.keys(requested)) Images.reindex_images(Map.keys(requested))
end)
gallery
end end
defp position_order(%{order_position_asc: true}), do: [asc: :position] defp position_order(%{order_position_asc: true}), do: [asc: :position]

View file

@ -16,9 +16,11 @@ defmodule Philomena.Images do
alias Philomena.Images.Uploader alias Philomena.Images.Uploader
alias Philomena.Images.Tagging alias Philomena.Images.Tagging
alias Philomena.Images.ElasticsearchIndex, as: ImageIndex alias Philomena.Images.ElasticsearchIndex, as: ImageIndex
alias Philomena.IndexWorker
alias Philomena.ImageFeatures.ImageFeature alias Philomena.ImageFeatures.ImageFeature
alias Philomena.SourceChanges.SourceChange alias Philomena.SourceChanges.SourceChange
alias Philomena.Notifications.Notification alias Philomena.Notifications.Notification
alias Philomena.NotificationWorker
alias Philomena.TagChanges.TagChange alias Philomena.TagChanges.TagChange
alias Philomena.Tags alias Philomena.Tags
alias Philomena.UserStatistics alias Philomena.UserStatistics
@ -644,18 +646,13 @@ defmodule Philomena.Images do
end end
def reindex_image(%Image{} = image) do def reindex_image(%Image{} = image) do
reindex_images([image.id]) Exq.enqueue(Exq, "indexing", IndexWorker, ["Images", "id", [image.id]])
image image
end end
def reindex_images(image_ids) do def reindex_images(image_ids) do
spawn(fn -> Exq.enqueue(Exq, "indexing", IndexWorker, ["Images", "id", image_ids])
Image
|> preload(^indexing_preloads())
|> where([i], i.id in ^image_ids)
|> Elasticsearch.reindex(Image)
end)
image_ids image_ids
end end
@ -673,6 +670,13 @@ defmodule Philomena.Images do
] ]
end end
def perform_reindex(column, condition) do
Image
|> preload(^indexing_preloads())
|> where([i], field(i, ^column) in ^condition)
|> Elasticsearch.reindex(Image)
end
alias Philomena.Images.Subscription alias Philomena.Images.Subscription
def subscribed?(_image, nil), do: false def subscribed?(_image, nil), do: false
@ -740,7 +744,12 @@ defmodule Philomena.Images do
end end
def notify_merge(source, target) do def notify_merge(source, target) do
spawn(fn -> Exq.enqueue(Exq, "notifications", NotificationWorker, ["Images", [source.id, target.id]])
end
def perform_notify([source_id, target_id]) do
target = get_image!(target_id)
subscriptions = subscriptions =
target target
|> Repo.preload(:subscriptions) |> Repo.preload(:subscriptions)
@ -754,10 +763,9 @@ defmodule Philomena.Images do
actor_type: "Image", actor_type: "Image",
actor_child_id: nil, actor_child_id: nil,
actor_child_type: nil, actor_child_type: nil,
action: "merged ##{source.id} into" action: "merged ##{source_id} into"
} }
) )
end)
end end
def clear_notification(_image, nil), do: nil def clear_notification(_image, nil), do: nil

View file

@ -12,8 +12,10 @@ defmodule Philomena.Posts do
alias Philomena.Topics alias Philomena.Topics
alias Philomena.Posts.Post alias Philomena.Posts.Post
alias Philomena.Posts.ElasticsearchIndex, as: PostIndex alias Philomena.Posts.ElasticsearchIndex, as: PostIndex
alias Philomena.IndexWorker
alias Philomena.Forums.Forum alias Philomena.Forums.Forum
alias Philomena.Notifications alias Philomena.Notifications
alias Philomena.NotificationWorker
alias Philomena.Versions alias Philomena.Versions
alias Philomena.Reports alias Philomena.Reports
alias Philomena.Reports.Report alias Philomena.Reports.Report
@ -93,7 +95,12 @@ defmodule Philomena.Posts do
end end
def notify_post(post) do def notify_post(post) do
spawn(fn -> Exq.enqueue(Exq, "notifications", NotificationWorker, ["Posts", post.id])
end
def perform_notify(post_id) do
post = get_post!(post_id)
topic = topic =
post post
|> Repo.preload(:topic) |> Repo.preload(:topic)
@ -115,9 +122,6 @@ defmodule Philomena.Posts do
action: "posted a new reply in" action: "posted a new reply in"
} }
) )
end)
post
end end
@doc """ @doc """
@ -232,13 +236,7 @@ defmodule Philomena.Posts do
end end
def reindex_post(%Post{} = post) do def reindex_post(%Post{} = post) do
spawn(fn -> Exq.enqueue(Exq, "indexing", IndexWorker, ["Posts", "id", [post.id]])
Post
|> preload(^indexing_preloads())
|> where(id: ^post.id)
|> Repo.one()
|> Elasticsearch.index_document(Post)
end)
post post
end end
@ -246,4 +244,11 @@ defmodule Philomena.Posts do
def indexing_preloads do def indexing_preloads do
[:user, topic: :forum] [:user, topic: :forum]
end end
def perform_reindex(column, condition) do
Post
|> preload(^indexing_preloads())
|> where([p], field(p, ^column) in ^condition)
|> Elasticsearch.reindex(Post)
end
end end

View file

@ -9,6 +9,7 @@ defmodule Philomena.Reports do
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.Reports.Report alias Philomena.Reports.Report
alias Philomena.Reports.ElasticsearchIndex, as: ReportIndex alias Philomena.Reports.ElasticsearchIndex, as: ReportIndex
alias Philomena.IndexWorker
alias Philomena.Polymorphic alias Philomena.Polymorphic
@doc """ @doc """
@ -143,24 +144,26 @@ defmodule Philomena.Reports do
defp maybe_reindex_report(result), do: result defp maybe_reindex_report(result), do: result
def reindex_reports(report_ids) do def reindex_reports(report_ids) do
spawn(fn -> Exq.enqueue(Exq, "indexing", IndexWorker, ["Reports", "id", report_ids])
Report
|> where([r], r.id in ^report_ids)
|> preload([:user, :admin])
|> Repo.all()
|> Polymorphic.load_polymorphic(reportable: [reportable_id: :reportable_type])
|> Enum.map(&Elasticsearch.index_document(&1, Report))
end)
report_ids report_ids
end end
def reindex_report(%Report{} = report) do def reindex_report(%Report{} = report) do
reindex_reports([report.id]) Exq.enqueue(Exq, "indexing", IndexWorker, ["Reports", "id", [report.id]])
report report
end end
def perform_reindex(column, condition) do
Report
|> where([r], field(r, ^column) in ^condition)
|> preload([:user, :admin])
|> Repo.all()
|> Polymorphic.load_polymorphic(reportable: [reportable_id: :reportable_type])
|> Enum.map(&Elasticsearch.index_document(&1, Report))
end
def count_reports(user) do def count_reports(user) do
if Canada.Can.can?(user, :index, Report) do if Canada.Can.can?(user, :index, Report) do
Report Report

View file

@ -7,6 +7,11 @@ defmodule Philomena.Tags do
alias Philomena.Repo alias Philomena.Repo
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.IndexWorker
alias Philomena.TagAliasWorker
alias Philomena.TagUnaliasWorker
alias Philomena.TagReindexWorker
alias Philomena.TagDeleteWorker
alias Philomena.Tags.Tag alias Philomena.Tags.Tag
alias Philomena.Tags.Uploader alias Philomena.Tags.Uploader
alias Philomena.Images alias Philomena.Images
@ -73,7 +78,7 @@ defmodule Philomena.Tags do
** (Ecto.NoResultsError) ** (Ecto.NoResultsError)
""" """
def get_tag!(slug), do: Repo.get_by!(Tag, slug: slug) def get_tag!(id), do: Repo.get!(Tag, id)
@doc """ @doc """
Creates a tag. Creates a tag.
@ -162,6 +167,14 @@ defmodule Philomena.Tags do
""" """
def delete_tag(%Tag{} = tag) do def delete_tag(%Tag{} = tag) do
Exq.enqueue(Exq, "indexing", TagDeleteWorker, [tag.id])
{:ok, tag}
end
def perform_delete(tag_id) do
tag = get_tag!(tag_id)
image_ids = image_ids =
Image Image
|> join(:inner, [i], _ in assoc(i, :tags)) |> join(:inner, [i], _ in assoc(i, :tags))
@ -188,9 +201,7 @@ defmodule Philomena.Tags do
|> Repo.update() |> Repo.update()
|> case do |> case do
{:ok, tag} -> {:ok, tag} ->
spawn(fn -> Exq.enqueue(Exq, "indexing", TagAliasWorker, [tag.id, target_tag.id])
perform_alias(tag, target_tag)
end)
{:ok, tag} {:ok, tag}
@ -199,7 +210,10 @@ defmodule Philomena.Tags do
end end
end end
defp perform_alias(tag, target_tag) do def perform_alias(tag_id, target_tag_id) do
tag = get_tag!(tag_id)
target_tag = get_tag!(target_tag_id)
filters_hidden = filters_hidden =
where(Filter, [f], fragment("? @> ARRAY[?]::integer[]", f.hidden_tag_ids, ^tag.id)) where(Filter, [f], fragment("? @> ARRAY[?]::integer[]", f.hidden_tag_ids, ^tag.id))
@ -253,6 +267,14 @@ defmodule Philomena.Tags do
end end
def reindex_tag_images(%Tag{} = tag) do def reindex_tag_images(%Tag{} = tag) do
Exq.enqueue(Exq, "indexing", TagReindexWorker, [tag.id])
{:ok, tag}
end
def perform_reindex_images(tag_id) do
tag = get_tag!(tag_id)
# First recount the tag # First recount the tag
image_count = image_count =
Image Image
@ -273,6 +295,13 @@ defmodule Philomena.Tags do
end end
def unalias_tag(%Tag{} = tag) do def unalias_tag(%Tag{} = tag) do
Exq.enqueue(Exq, "indexing", TagUnaliasWorker, [tag.id])
{:ok, tag}
end
def perform_unalias(tag_id) do
tag = get_tag!(tag_id)
former_alias = Repo.preload(tag, :aliased_tag).aliased_tag former_alias = Repo.preload(tag, :aliased_tag).aliased_tag
tag tag
@ -352,20 +381,13 @@ defmodule Philomena.Tags do
end end
def reindex_tag(%Tag{} = tag) do def reindex_tag(%Tag{} = tag) do
reindex_tags([%Tag{id: tag.id}]) Exq.enqueue(Exq, "indexing", IndexWorker, ["Tags", "id", [tag.id]])
tag
end end
def reindex_tags(tags) do def reindex_tags(tags) do
spawn(fn -> Exq.enqueue(Exq, "indexing", IndexWorker, ["Tags", "id", Enum.map(tags, & &1.id)])
ids =
tags
|> Enum.map(& &1.id)
Tag
|> preload(^indexing_preloads())
|> where([t], t.id in ^ids)
|> Elasticsearch.reindex(Tag)
end)
tags tags
end end
@ -374,6 +396,13 @@ defmodule Philomena.Tags do
[:aliased_tag, :aliases, :implied_tags, :implied_by_tags] [:aliased_tag, :aliases, :implied_tags, :implied_by_tags]
end end
def perform_reindex(column, condition) do
Tag
|> preload(^indexing_preloads())
|> where([t], field(t, ^column) in ^condition)
|> Elasticsearch.reindex(Tag)
end
alias Philomena.Tags.Implication alias Philomena.Tags.Implication
@doc """ @doc """

View file

@ -9,7 +9,9 @@ defmodule Philomena.Topics do
alias Philomena.Topics.Topic alias Philomena.Topics.Topic
alias Philomena.Forums.Forum alias Philomena.Forums.Forum
alias Philomena.Posts
alias Philomena.Notifications alias Philomena.Notifications
alias Philomena.NotificationWorker
@doc """ @doc """
Gets a single topic. Gets a single topic.
@ -74,7 +76,13 @@ defmodule Philomena.Topics do
end end
def notify_topic(topic, post) do def notify_topic(topic, post) do
spawn(fn -> Exq.enqueue(Exq, "notifications", NotificationWorker, ["Topics", [topic.id, post.id]])
end
def perform_notify([topic_id, post_id]) do
topic = get_topic!(topic_id)
post = Posts.get_post!(post_id)
forum = forum =
topic topic
|> Repo.preload(:forum) |> Repo.preload(:forum)
@ -96,9 +104,6 @@ defmodule Philomena.Topics do
action: "posted a new topic in #{forum.name}" action: "posted a new topic in #{forum.name}"
} }
) )
end)
topic
end end
@doc """ @doc """

View file

@ -1,6 +1,7 @@
defmodule Philomena.UserDownvoteWipe do defmodule Philomena.UserDownvoteWipe do
alias Philomena.Batch alias Philomena.Batch
alias Philomena.Elasticsearch alias Philomena.Elasticsearch
alias Philomena.Users
alias Philomena.Users.User alias Philomena.Users.User
alias Philomena.Images.Image alias Philomena.Images.Image
alias Philomena.Images alias Philomena.Images
@ -9,7 +10,9 @@ defmodule Philomena.UserDownvoteWipe do
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
def perform(user, upvotes_and_faves_too \\ false) do def perform(user_id, upvotes_and_faves_too \\ false) do
user = Users.get_user!(user_id)
ImageVote ImageVote
|> where(user_id: ^user.id, up: false) |> where(user_id: ^user.id, up: false)
|> Batch.query_batches([id_field: :image_id], fn queryable -> |> Batch.query_batches([id_field: :image_id], fn queryable ->

View file

@ -10,11 +10,14 @@ defmodule Philomena.UserWipe do
alias Philomena.TagChanges.TagChange alias Philomena.TagChanges.TagChange
alias Philomena.UserIps.UserIp alias Philomena.UserIps.UserIp
alias Philomena.UserFingerprints.UserFingerprint alias Philomena.UserFingerprints.UserFingerprint
alias Philomena.Users
alias Philomena.Users.User alias Philomena.Users.User
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
def perform(user) do def perform(user_id) do
user = Users.get_user!(user_id)
random_hex = :crypto.strong_rand_bytes(16) |> Base.encode16(case: :lower) random_hex = :crypto.strong_rand_bytes(16) |> Base.encode16(case: :lower)
for schema <- [Comment, Image, Post, Report, SourceChange, TagChange] do for schema <- [Comment, Image, Post, Report, SourceChange, TagChange] do

View file

@ -17,6 +17,7 @@ defmodule Philomena.Users do
alias Philomena.Posts alias Philomena.Posts
alias Philomena.Galleries alias Philomena.Galleries
alias Philomena.Reports alias Philomena.Reports
alias Philomena.UserRenameWorker
## Database getters ## Database getters
@ -604,13 +605,7 @@ defmodule Philomena.Users do
|> Repo.transaction() |> Repo.transaction()
|> case do |> case do
{:ok, %{account: %{name: new_name} = account}} -> {:ok, %{account: %{name: new_name} = account}} ->
spawn(fn -> Exq.enqueue(Exq, "indexing", UserRenameWorker, [old_name, new_name])
Images.user_name_reindex(old_name, new_name)
Comments.user_name_reindex(old_name, new_name)
Posts.user_name_reindex(old_name, new_name)
Galleries.user_name_reindex(old_name, new_name)
Reports.user_name_reindex(old_name, new_name)
end)
{:ok, account} {:ok, account}
@ -619,6 +614,14 @@ defmodule Philomena.Users do
end end
end end
def perform_rename(old_name, new_name) do
Images.user_name_reindex(old_name, new_name)
Comments.user_name_reindex(old_name, new_name)
Posts.user_name_reindex(old_name, new_name)
Galleries.user_name_reindex(old_name, new_name)
Reports.user_name_reindex(old_name, new_name)
end
def reactivate_user(%User{} = user) do def reactivate_user(%User{} = user) do
user user
|> User.reactivate_changeset() |> User.reactivate_changeset()

View file

@ -0,0 +1,7 @@
defmodule Philomena.GalleryReorderWorker do
alias Philomena.Galleries
def perform(gallery_id, image_ids) do
Galleries.perform_reorder(gallery_id, image_ids)
end
end

View file

@ -0,0 +1,23 @@
defmodule Philomena.IndexWorker do
@modules %{
"Comments" => Philomena.Comments,
"Galleries" => Philomena.Galleries,
"Images" => Philomena.Images,
"Posts" => Philomena.Posts,
"Reports" => Philomena.Reports,
"Tags" => Philomena.Tags
}
# Perform the queued index. Context function looks like the following:
#
# def perform_reindex(column, condition) do
# Image
# |> preload(^indexing_preloads())
# |> where([i], field(i, ^column) in ^condition)
# |> Elasticsearch.reindex(Image)
# end
#
def perform(module, column, condition) do
@modules[module].perform_reindex(String.to_existing_atom(column), condition)
end
end

View file

@ -0,0 +1,13 @@
defmodule Philomena.NotificationWorker do
@modules %{
"Comments" => Philomena.Comments,
"Galleries" => Philomena.Galleries,
"Images" => Philomena.Images,
"Posts" => Philomena.Posts,
"Topics" => Philomena.Topics
}
def perform(module, args) do
@modules[module].perform_notify(args)
end
end

View file

@ -0,0 +1,7 @@
defmodule Philomena.TagAliasWorker do
alias Philomena.Tags
def perform(tag_id, target_tag_id) do
Tags.perform_alias(tag_id, target_tag_id)
end
end

View file

@ -0,0 +1,7 @@
defmodule Philomena.TagDeleteWorker do
alias Philomena.Tags
def perform(tag_id) do
Tags.perform_delete(tag_id)
end
end

View file

@ -0,0 +1,7 @@
defmodule Philomena.TagReindexWorker do
alias Philomena.Tags
def perform(tag_id) do
Tags.perform_reindex_images(tag_id)
end
end

View file

@ -0,0 +1,7 @@
defmodule Philomena.TagUnaliasWorker do
alias Philomena.Tags
def perform(tag_id) do
Tags.perform_unalias(tag_id)
end
end

View file

@ -0,0 +1,7 @@
defmodule Philomena.UserRenameWorker do
alias Philomena.Users
def perform(old_name, new_name) do
Users.perform_rename(old_name, new_name)
end
end

View file

@ -0,0 +1,7 @@
defmodule Philomena.UserUnvoteWorker do
alias Philomena.UserDownvoteWipe
def perform(user_id, votes_and_faves_too?) do
UserDownvoteWipe.perform(user_id, votes_and_faves_too?)
end
end

View file

@ -0,0 +1,7 @@
defmodule Philomena.UserWipeWorker do
alias Philomena.UserWipe
def perform(user_id) do
UserWipe.perform(user_id)
end
end

View file

@ -1,16 +1,14 @@
defmodule PhilomenaWeb.Admin.User.DownvoteController do defmodule PhilomenaWeb.Admin.User.DownvoteController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias Philomena.UserDownvoteWipe alias Philomena.UserUnvoteWorker
alias Philomena.Users.User alias Philomena.Users.User
plug :verify_authorized plug :verify_authorized
plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true
def delete(conn, _params) do def delete(conn, _params) do
spawn(fn -> Exq.enqueue(Exq, "indexing", UserUnvoteWorker, [conn.assigns.user.id, false])
UserDownvoteWipe.perform(conn.assigns.user)
end)
conn conn
|> put_flash(:info, "Downvote wipe started.") |> put_flash(:info, "Downvote wipe started.")

View file

@ -1,16 +1,14 @@
defmodule PhilomenaWeb.Admin.User.VoteController do defmodule PhilomenaWeb.Admin.User.VoteController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias Philomena.UserDownvoteWipe alias Philomena.UserUnvoteWorker
alias Philomena.Users.User alias Philomena.Users.User
plug :verify_authorized plug :verify_authorized
plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true
def delete(conn, _params) do def delete(conn, _params) do
spawn(fn -> Exq.enqueue(Exq, "indexing", UserUnvoteWorker, [conn.assigns.user.id, true])
UserDownvoteWipe.perform(conn.assigns.user, true)
end)
conn conn
|> put_flash(:info, "Vote and fave wipe started.") |> put_flash(:info, "Vote and fave wipe started.")

View file

@ -1,21 +1,19 @@
defmodule PhilomenaWeb.Admin.User.WipeController do defmodule PhilomenaWeb.Admin.User.WipeController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias Philomena.UserWipe alias Philomena.UserWipeWorker
alias Philomena.Users.User alias Philomena.Users.User
plug :verify_authorized plug :verify_authorized
plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true
def create(conn, _params) do def create(conn, _params) do
spawn(fn -> Exq.enqueue(Exq, "indexing", UserWipeWorker, [conn.assigns.user.id])
UserWipe.perform(conn.assigns.user)
end)
conn conn
|> put_flash( |> put_flash(
:info, :info,
"PII wipe started, please verify and then deactivate the account as necessary." "PII wipe queued, please verify and then deactivate the account as necessary."
) )
|> redirect(to: Routes.profile_path(conn, :show, conn.assigns.user)) |> redirect(to: Routes.profile_path(conn, :show, conn.assigns.user))
end end

View file

@ -31,12 +31,10 @@ defmodule PhilomenaWeb.Tag.AliasController do
end end
def delete(conn, _params) do def delete(conn, _params) do
spawn(fn -> {:ok, tag} = Tags.unalias_tag(conn.assigns.tag)
{:ok, _tag} = Tags.unalias_tag(conn.assigns.tag)
end)
conn conn
|> put_flash(:info, "Tag dealias queued.") |> put_flash(:info, "Tag dealias queued.")
|> redirect(to: Routes.tag_path(conn, :show, conn.assigns.tag)) |> redirect(to: Routes.tag_path(conn, :show, tag))
end end
end end

View file

@ -14,12 +14,10 @@ defmodule PhilomenaWeb.Tag.ReindexController do
persisted: true persisted: true
def create(conn, _params) do def create(conn, _params) do
spawn(fn -> {:ok, tag} = Tags.reindex_tag_images(conn.assigns.tag)
Tags.reindex_tag_images(conn.assigns.tag)
end)
conn conn
|> put_flash(:info, "Tag reindex started.") |> put_flash(:info, "Tag reindex started.")
|> redirect(to: Routes.tag_path(conn, :edit, conn.assigns.tag)) |> redirect(to: Routes.tag_path(conn, :edit, tag))
end end
end end

View file

@ -107,12 +107,10 @@ defmodule PhilomenaWeb.TagController do
end end
def delete(conn, _params) do def delete(conn, _params) do
spawn(fn -> {:ok, _tag} = Tags.delete_tag(conn.assigns.tag)
Tags.delete_tag(conn.assigns.tag)
end)
conn conn
|> put_flash(:info, "Tag scheduled for deletion.") |> put_flash(:info, "Tag queued for deletion.")
|> redirect(to: "/") |> redirect(to: "/")
end end