Use oban for search indexing

This commit is contained in:
Ekaterina Vaartis 2022-01-22 15:23:11 +03:00 committed by FloatingGhost
parent 54b2a86f47
commit 5def4a7d49
3 changed files with 27 additions and 12 deletions

View file

@ -568,7 +568,8 @@
remote_fetcher: 2,
attachments_cleanup: 1,
new_users_digest: 1,
mute_expire: 5
mute_expire: 5,
search_indexing: 1
],
plugins: [Oban.Plugins.Pruner],
crontab: [

View file

@ -1,19 +1,12 @@
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

View file

@ -0,0 +1,21 @@
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