defmodule Pleroma.Search do
- def add_to_index(activity) do
- search_module = Pleroma.Config.get([Pleroma.Search, :module])
+ alias Pleroma.Workers.SearchIndexingWorker
- ConcurrentLimiter.limit(Pleroma.Search, fn ->
- Task.start(fn -> search_module.add_to_index(activity) end)
- end)
+ def add_to_index(activity) do
+ SearchIndexingWorker.enqueue("add_to_index", %{"activity" => activity.id})
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)
+ SearchIndexingWorker.enqueue("remove_from_index", %{"object" => object.id})
end
def search(query, options) do
--- /dev/null
+defmodule Pleroma.Workers.SearchIndexingWorker do
+ use Pleroma.Workers.WorkerHelper, queue: "search_indexing"
+
+ @impl Oban.Worker
+
+ def perform(%Job{args: %{"op" => "add_to_index", "activity" => activity_id}}) do
+ activity = Pleroma.Activity.get_by_id_with_object(activity_id)
+
+ search_module = Pleroma.Config.get([Pleroma.Search, :module])
+
+ search_module.add_to_index(activity)
+ end
+
+ def perform(%Job{args: %{"op" => "remove_from_index", "object" => object_id}}) do
+ object = Pleroma.Object.get_by_id(object_id)
+
+ search_module = Pleroma.Config.get([Pleroma.Search, :module])
+
+ search_module.remove_from_index(object)
+ end
+end