Use oban for search indexing
This commit is contained in:
parent
54b2a86f47
commit
5def4a7d49
3 changed files with 27 additions and 12 deletions
|
@ -568,7 +568,8 @@ config :pleroma, Oban,
|
||||||
remote_fetcher: 2,
|
remote_fetcher: 2,
|
||||||
attachments_cleanup: 1,
|
attachments_cleanup: 1,
|
||||||
new_users_digest: 1,
|
new_users_digest: 1,
|
||||||
mute_expire: 5
|
mute_expire: 5,
|
||||||
|
search_indexing: 1
|
||||||
],
|
],
|
||||||
plugins: [Oban.Plugins.Pruner],
|
plugins: [Oban.Plugins.Pruner],
|
||||||
crontab: [
|
crontab: [
|
||||||
|
|
|
@ -1,19 +1,12 @@
|
||||||
defmodule Pleroma.Search do
|
defmodule Pleroma.Search do
|
||||||
def add_to_index(activity) do
|
alias Pleroma.Workers.SearchIndexingWorker
|
||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
|
||||||
|
|
||||||
ConcurrentLimiter.limit(Pleroma.Search, fn ->
|
def add_to_index(activity) do
|
||||||
Task.start(fn -> search_module.add_to_index(activity) end)
|
SearchIndexingWorker.enqueue("add_to_index", %{"activity" => activity.id})
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_from_index(object) do
|
def remove_from_index(object) do
|
||||||
# Also delete from search index
|
SearchIndexingWorker.enqueue("remove_from_index", %{"object" => object.id})
|
||||||
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
|
||||||
|
|
||||||
def search(query, options) do
|
def search(query, options) do
|
||||||
|
|
21
lib/pleroma/workers/search_indexing_worker.ex
Normal file
21
lib/pleroma/workers/search_indexing_worker.ex
Normal 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
|
Loading…
Reference in a new issue