Don't create noop SearchIndexingWorker jobs for passive index
This commit is contained in:
parent
ed4019e7a3
commit
d283ac52c3
3 changed files with 24 additions and 13 deletions
|
@ -40,12 +40,6 @@ def search(user, search_query, options \\ []) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
|
||||||
def add_to_index(_activity), do: nil
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def remove_from_index(_object), do: nil
|
|
||||||
|
|
||||||
def maybe_restrict_author(query, %User{} = author) do
|
def maybe_restrict_author(query, %User{} = author) do
|
||||||
Activity.Queries.by_author(query, author)
|
Activity.Queries.by_author(query, author)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,4 +14,6 @@ defmodule Pleroma.Search.SearchBackend do
|
||||||
from index.
|
from index.
|
||||||
"""
|
"""
|
||||||
@callback remove_from_index(object :: Pleroma.Object.t()) :: {:ok, any()} | {:error, any()}
|
@callback remove_from_index(object :: Pleroma.Object.t()) :: {:ok, any()} | {:error, any()}
|
||||||
|
|
||||||
|
@optional_callbacks add_to_index: 1, remove_from_index: 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,23 +1,38 @@
|
||||||
defmodule Pleroma.Workers.SearchIndexingWorker do
|
defmodule Pleroma.Workers.SearchIndexingWorker do
|
||||||
use Pleroma.Workers.WorkerHelper, queue: "search_indexing"
|
use Pleroma.Workers.WorkerHelper, queue: "search_indexing"
|
||||||
|
|
||||||
@impl Oban.Worker
|
defp search_module(), do: Pleroma.Config.get!([Pleroma.Search, :module])
|
||||||
|
|
||||||
|
def enqueue("add_to_index", params, worker_args) do
|
||||||
|
if Kernel.function_exported?(search_module(), :add_to_index, 1) do
|
||||||
|
do_enqueue("add_to_index", params, worker_args)
|
||||||
|
else
|
||||||
|
# XXX: or {:ok, nil} to more closely match Oban.inset()'s {:ok, job}?
|
||||||
|
# or similar to unique coflict: %Oban.Job{conflict?: true} (but omitting all other fileds...)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def enqueue("remove_from_index", params, worker_args) do
|
||||||
|
if Kernel.function_exported?(search_module(), :remove_from_index, 1) do
|
||||||
|
do_enqueue("remove_from_index", params, worker_args)
|
||||||
|
else
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl Oban.Worker
|
||||||
def perform(%Job{args: %{"op" => "add_to_index", "activity" => activity_id}}) do
|
def perform(%Job{args: %{"op" => "add_to_index", "activity" => activity_id}}) do
|
||||||
activity = Pleroma.Activity.get_by_id_with_object(activity_id)
|
activity = Pleroma.Activity.get_by_id_with_object(activity_id)
|
||||||
|
|
||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
search_module().add_to_index(activity)
|
||||||
|
|
||||||
search_module.add_to_index(activity)
|
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform(%Job{args: %{"op" => "remove_from_index", "object" => object_id}}) do
|
def perform(%Job{args: %{"op" => "remove_from_index", "object" => object_id}}) do
|
||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
|
||||||
|
|
||||||
# Fake the object so we can remove it from the index without having to keep it in the DB
|
# Fake the object so we can remove it from the index without having to keep it in the DB
|
||||||
search_module.remove_from_index(%Pleroma.Object{id: object_id})
|
search_module().remove_from_index(%Pleroma.Object{id: object_id})
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue