mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
remove controller reindex from posts, tags, reports
This commit is contained in:
parent
d567d5ffc0
commit
75be0794c0
9 changed files with 58 additions and 27 deletions
|
@ -92,6 +92,15 @@ defmodule Philomena.Posts do
|
||||||
Topics.create_subscription(topic, attributes[:user])
|
Topics.create_subscription(topic, attributes[:user])
|
||||||
end)
|
end)
|
||||||
|> Repo.transaction()
|
|> Repo.transaction()
|
||||||
|
|> case do
|
||||||
|
{:ok, %{post: post}} = result ->
|
||||||
|
reindex_post(post)
|
||||||
|
|
||||||
|
result
|
||||||
|
|
||||||
|
error ->
|
||||||
|
error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_post(post) do
|
def notify_post(post) do
|
||||||
|
@ -152,6 +161,15 @@ defmodule Philomena.Posts do
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|> Repo.transaction()
|
|> Repo.transaction()
|
||||||
|
|> case do
|
||||||
|
{:ok, %{post: post}} = result ->
|
||||||
|
reindex_post(post)
|
||||||
|
|
||||||
|
result
|
||||||
|
|
||||||
|
error ->
|
||||||
|
error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -199,21 +217,14 @@ defmodule Philomena.Posts do
|
||||||
post
|
post
|
||||||
|> Post.unhide_changeset()
|
|> Post.unhide_changeset()
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|> case do
|
|> reindex_after_update()
|
||||||
{:ok, post} ->
|
|
||||||
reindex_post(post)
|
|
||||||
|
|
||||||
{:ok, post}
|
|
||||||
|
|
||||||
error ->
|
|
||||||
error
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_post(%Post{} = post) do
|
def destroy_post(%Post{} = post) do
|
||||||
post
|
post
|
||||||
|> Post.destroy_changeset()
|
|> Post.destroy_changeset()
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
|> reindex_after_update()
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -235,6 +246,16 @@ defmodule Philomena.Posts do
|
||||||
Elasticsearch.update_by_query(Post, data.query, data.set_replacements, data.replacements)
|
Elasticsearch.update_by_query(Post, data.query, data.set_replacements, data.replacements)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp reindex_after_update({:ok, post}) do
|
||||||
|
reindex_post(post)
|
||||||
|
|
||||||
|
{:ok, post}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp reindex_after_update(result) do
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
def reindex_post(%Post{} = post) do
|
def reindex_post(%Post{} = post) do
|
||||||
Exq.enqueue(Exq, "indexing", IndexWorker, ["Posts", "id", [post.id]])
|
Exq.enqueue(Exq, "indexing", IndexWorker, ["Posts", "id", [post.id]])
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ defmodule Philomena.Reports do
|
||||||
%Report{reportable_id: reportable_id, reportable_type: reportable_type}
|
%Report{reportable_id: reportable_id, reportable_type: reportable_type}
|
||||||
|> Report.creation_changeset(attrs, attribution)
|
|> Report.creation_changeset(attrs, attribution)
|
||||||
|> Repo.insert()
|
|> Repo.insert()
|
||||||
|> maybe_reindex_report()
|
|> reindex_after_update()
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -76,7 +76,7 @@ defmodule Philomena.Reports do
|
||||||
report
|
report
|
||||||
|> Report.changeset(attrs)
|
|> Report.changeset(attrs)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|> maybe_reindex_report()
|
|> reindex_after_update()
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -112,21 +112,21 @@ defmodule Philomena.Reports do
|
||||||
report
|
report
|
||||||
|> Report.claim_changeset(user)
|
|> Report.claim_changeset(user)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|> maybe_reindex_report()
|
|> reindex_after_update()
|
||||||
end
|
end
|
||||||
|
|
||||||
def unclaim_report(%Report{} = report) do
|
def unclaim_report(%Report{} = report) do
|
||||||
report
|
report
|
||||||
|> Report.unclaim_changeset()
|
|> Report.unclaim_changeset()
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|> maybe_reindex_report()
|
|> reindex_after_update()
|
||||||
end
|
end
|
||||||
|
|
||||||
def close_report(%Report{} = report, user) do
|
def close_report(%Report{} = report, user) do
|
||||||
report
|
report
|
||||||
|> Report.close_changeset(user)
|
|> Report.close_changeset(user)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|> maybe_reindex_report()
|
|> reindex_after_update()
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_name_reindex(old_name, new_name) do
|
def user_name_reindex(old_name, new_name) do
|
||||||
|
@ -135,13 +135,15 @@ defmodule Philomena.Reports do
|
||||||
Elasticsearch.update_by_query(Report, data.query, data.set_replacements, data.replacements)
|
Elasticsearch.update_by_query(Report, data.query, data.set_replacements, data.replacements)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_reindex_report({:ok, report} = result) do
|
defp reindex_after_update({:ok, report}) do
|
||||||
reindex_report(report)
|
reindex_report(report)
|
||||||
|
|
||||||
result
|
{:ok, report}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_reindex_report(result), do: result
|
defp reindex_after_update(result) do
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
def reindex_reports(report_ids) do
|
def reindex_reports(report_ids) do
|
||||||
Exq.enqueue(Exq, "indexing", IndexWorker, ["Reports", "id", report_ids])
|
Exq.enqueue(Exq, "indexing", IndexWorker, ["Reports", "id", report_ids])
|
||||||
|
|
|
@ -121,6 +121,15 @@ defmodule Philomena.Tags do
|
||||||
tag
|
tag
|
||||||
|> Tag.changeset(attrs, implied_tags)
|
|> Tag.changeset(attrs, implied_tags)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
|> case do
|
||||||
|
{:ok, tag} ->
|
||||||
|
reindex_tag(tag)
|
||||||
|
|
||||||
|
{:ok, tag}
|
||||||
|
|
||||||
|
error ->
|
||||||
|
error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_tag_image(%Tag{} = tag, attrs) do
|
def update_tag_image(%Tag{} = tag, attrs) do
|
||||||
|
|
|
@ -73,6 +73,15 @@ defmodule Philomena.Topics do
|
||||||
create_subscription(topic, attribution[:user])
|
create_subscription(topic, attribution[:user])
|
||||||
end)
|
end)
|
||||||
|> Repo.transaction()
|
|> Repo.transaction()
|
||||||
|
|> case do
|
||||||
|
{:ok, %{topic: topic}} = result ->
|
||||||
|
Posts.reindex_post(hd(topic.posts))
|
||||||
|
|
||||||
|
result
|
||||||
|
|
||||||
|
error ->
|
||||||
|
error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_topic(topic, post) do
|
def notify_topic(topic, post) do
|
||||||
|
|
|
@ -48,8 +48,6 @@ defmodule PhilomenaWeb.ReportController do
|
||||||
_falsy ->
|
_falsy ->
|
||||||
case Reports.create_report(reportable.id, reportable_type, attribution, report_params) do
|
case Reports.create_report(reportable.id, reportable_type, attribution, report_params) do
|
||||||
{:ok, report} ->
|
{:ok, report} ->
|
||||||
Reports.reindex_report(report)
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
:info,
|
:info,
|
||||||
|
|
|
@ -95,8 +95,6 @@ defmodule PhilomenaWeb.TagController do
|
||||||
def update(conn, %{"tag" => tag_params}) do
|
def update(conn, %{"tag" => tag_params}) do
|
||||||
case Tags.update_tag(conn.assigns.tag, tag_params) do
|
case Tags.update_tag(conn.assigns.tag, tag_params) do
|
||||||
{:ok, tag} ->
|
{:ok, tag} ->
|
||||||
Tags.reindex_tag(tag)
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Tag successfully updated.")
|
|> put_flash(:info, "Tag successfully updated.")
|
||||||
|> redirect(to: Routes.tag_path(conn, :show, tag))
|
|> redirect(to: Routes.tag_path(conn, :show, tag))
|
||||||
|
|
|
@ -17,8 +17,6 @@ defmodule PhilomenaWeb.Topic.Post.DeleteController do
|
||||||
|
|
||||||
case Posts.destroy_post(post) do
|
case Posts.destroy_post(post) do
|
||||||
{:ok, post} ->
|
{:ok, post} ->
|
||||||
Posts.reindex_post(post)
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Post successfully destroyed!")
|
|> put_flash(:info, "Post successfully destroyed!")
|
||||||
|> redirect(
|
|> redirect(
|
||||||
|
|
|
@ -36,7 +36,6 @@ defmodule PhilomenaWeb.Topic.PostController do
|
||||||
case Posts.create_post(topic, attributes, post_params) do
|
case Posts.create_post(topic, attributes, post_params) do
|
||||||
{:ok, %{post: post}} ->
|
{:ok, %{post: post}} ->
|
||||||
Posts.notify_post(post)
|
Posts.notify_post(post)
|
||||||
Posts.reindex_post(post)
|
|
||||||
UserStatistics.inc_stat(conn.assigns.current_user, :forum_posts)
|
UserStatistics.inc_stat(conn.assigns.current_user, :forum_posts)
|
||||||
|
|
||||||
if forum.access_level == "normal" do
|
if forum.access_level == "normal" do
|
||||||
|
@ -77,8 +76,6 @@ defmodule PhilomenaWeb.Topic.PostController do
|
||||||
|
|
||||||
case Posts.update_post(post, user, post_params) do
|
case Posts.update_post(post, user, post_params) do
|
||||||
{:ok, _post} ->
|
{:ok, _post} ->
|
||||||
Posts.reindex_post(post)
|
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Post successfully edited.")
|
|> put_flash(:info, "Post successfully edited.")
|
||||||
|> redirect(
|
|> redirect(
|
||||||
|
|
|
@ -112,7 +112,6 @@ defmodule PhilomenaWeb.TopicController do
|
||||||
case Topics.create_topic(forum, attributes, topic_params) do
|
case Topics.create_topic(forum, attributes, topic_params) do
|
||||||
{:ok, %{topic: topic}} ->
|
{:ok, %{topic: topic}} ->
|
||||||
post = hd(topic.posts)
|
post = hd(topic.posts)
|
||||||
Posts.reindex_post(post)
|
|
||||||
Topics.notify_topic(topic, post)
|
Topics.notify_topic(topic, post)
|
||||||
|
|
||||||
if forum.access_level == "normal" do
|
if forum.access_level == "normal" do
|
||||||
|
|
Loading…
Reference in a new issue