Also index incoming federated posts
This commit is contained in:
parent
e35d87ea54
commit
2b2e409ad7
|
@ -0,0 +1,18 @@
|
|||
defmodule Pleroma.Search do
|
||||
def add_to_index(activity) do
|
||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||
|
||||
ConcurrentLimiter.limit(Pleroma.Search, fn ->
|
||||
Task.start(fn -> search_module.add_to_index(activity) end)
|
||||
end)
|
||||
end
|
||||
|
||||
def remove_from_index(object) do
|
||||
# Also delete from search index
|
||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||
|
||||
ConcurrentLimiter.limit(Pleroma.Search, fn ->
|
||||
Task.start(fn -> search_module.remove_from_index(object) end)
|
||||
end)
|
||||
end
|
||||
end
|
|
@ -140,11 +140,8 @@ def insert(map, local \\ true, fake \\ false, bypass_actor_check \\ false) when
|
|||
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
||||
end)
|
||||
|
||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||
|
||||
ConcurrentLimiter.limit(Pleroma.Search, fn ->
|
||||
Task.start(fn -> search_module.add_to_index(activity) end)
|
||||
end)
|
||||
# Add local posts to search index
|
||||
Pleroma.Search.add_to_index(activity)
|
||||
|
||||
{:ok, activity}
|
||||
else
|
||||
|
|
|
@ -197,6 +197,7 @@ def handle(%{data: %{"type" => "Like"}} = object, meta) do
|
|||
# - Increase replies count
|
||||
# - Set up ActivityExpiration
|
||||
# - Set up notifications
|
||||
# - Index incoming posts for search (if needed)
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Create"}} = activity, meta) do
|
||||
with {:ok, object, meta} <- handle_object_creation(meta[:object_data], activity, meta),
|
||||
|
@ -226,6 +227,8 @@ def handle(%{data: %{"type" => "Create"}} = activity, meta) do
|
|||
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
||||
end)
|
||||
|
||||
Pleroma.Search.add_to_index(Map.put(activity, :object, object))
|
||||
|
||||
meta =
|
||||
meta
|
||||
|> add_notifications(notifications)
|
||||
|
@ -286,6 +289,7 @@ def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do
|
|||
# - Reduce the user note count
|
||||
# - Reduce the reply count
|
||||
# - Stream out the activity
|
||||
# - Removes posts from search index (if needed)
|
||||
@impl true
|
||||
def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
|
||||
deleted_object =
|
||||
|
@ -325,6 +329,9 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object,
|
|||
|
||||
if result == :ok do
|
||||
Notification.create_notifications(object)
|
||||
|
||||
Pleroma.Search.remove_from_index(object)
|
||||
|
||||
{:ok, object, meta}
|
||||
else
|
||||
{:error, result}
|
||||
|
|
|
@ -147,12 +147,8 @@ def delete(activity_id, user) do
|
|||
true <- User.superuser?(user) || user.ap_id == object.data["actor"],
|
||||
{:ok, delete_data, _} <- Builder.delete(user, object.data["id"]),
|
||||
{:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do
|
||||
# Also delete from search index
|
||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||
|
||||
ConcurrentLimiter.limit(Pleroma.Search, fn ->
|
||||
Task.start(fn -> search_module.remove_from_index(object) end)
|
||||
end)
|
||||
# Remove from search index for local posts
|
||||
Pleroma.Search.remove_from_index(object)
|
||||
|
||||
{:ok, delete}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue