mirror of
https://git.youjo.love/youjo/youjo-be.git
synced 2024-11-20 13:59:55 +01:00
Also index incoming federated posts
This commit is contained in:
parent
52a872432d
commit
b3401ba7bd
4 changed files with 29 additions and 11 deletions
18
lib/pleroma/search/search.ex
Normal file
18
lib/pleroma/search/search.ex
Normal file
|
@ -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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
# Add local posts to search index
|
||||||
|
Pleroma.Search.add_to_index(activity)
|
||||||
ConcurrentLimiter.limit(Pleroma.Search, fn ->
|
|
||||||
Task.start(fn -> search_module.add_to_index(activity) end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
|
|
|
@ -193,6 +193,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||||
# - Increase replies count
|
# - Increase replies count
|
||||||
# - Set up ActivityExpiration
|
# - Set up ActivityExpiration
|
||||||
# - Set up notifications
|
# - Set up notifications
|
||||||
|
# - Index incoming posts for search (if needed)
|
||||||
@impl true
|
@impl true
|
||||||
def handle(%{data: %{"type" => "Create"}} = activity, meta) do
|
def handle(%{data: %{"type" => "Create"}} = activity, meta) do
|
||||||
with {:ok, object, meta} <- handle_object_creation(meta[:object_data], activity, meta),
|
with {:ok, object, meta} <- handle_object_creation(meta[:object_data], activity, meta),
|
||||||
|
@ -222,6 +223,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||||
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
Task.start(fn -> Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Pleroma.Search.add_to_index(Map.put(activity, :object, object))
|
||||||
|
|
||||||
meta =
|
meta =
|
||||||
meta
|
meta
|
||||||
|> add_notifications(notifications)
|
|> add_notifications(notifications)
|
||||||
|
@ -281,6 +284,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||||
# - Reduce the user note count
|
# - Reduce the user note count
|
||||||
# - Reduce the reply count
|
# - Reduce the reply count
|
||||||
# - Stream out the activity
|
# - Stream out the activity
|
||||||
|
# - Removes posts from search index (if needed)
|
||||||
@impl true
|
@impl true
|
||||||
def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
|
def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
|
||||||
deleted_object =
|
deleted_object =
|
||||||
|
@ -320,6 +324,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||||
|
|
||||||
if result == :ok do
|
if result == :ok do
|
||||||
Notification.create_notifications(object)
|
Notification.create_notifications(object)
|
||||||
|
|
||||||
|
Pleroma.Search.remove_from_index(object)
|
||||||
|
|
||||||
{:ok, object, meta}
|
{:ok, object, meta}
|
||||||
else
|
else
|
||||||
{:error, result}
|
{:error, result}
|
||||||
|
|
|
@ -146,12 +146,8 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
true <- User.superuser?(user) || user.ap_id == object.data["actor"],
|
true <- User.superuser?(user) || user.ap_id == object.data["actor"],
|
||||||
{:ok, delete_data, _} <- Builder.delete(user, object.data["id"]),
|
{:ok, delete_data, _} <- Builder.delete(user, object.data["id"]),
|
||||||
{:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do
|
{:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do
|
||||||
# Also delete from search index
|
# Remove from search index for local posts
|
||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
Pleroma.Search.remove_from_index(object)
|
||||||
|
|
||||||
ConcurrentLimiter.limit(Pleroma.Search, fn ->
|
|
||||||
Task.start(fn -> search_module.remove_from_index(object) end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
{:ok, delete}
|
{:ok, delete}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue