Make add_to_index and remove_from_index report errors
This commit is contained in:
parent
102ebb42bd
commit
5ac6763238
|
@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
|||
import Ecto.Query
|
||||
|
||||
import Pleroma.Search.Meilisearch,
|
||||
only: [meili_post: 2, meili_put: 2, meili_get: 1, meili_delete!: 1]
|
||||
only: [meili_post: 2, meili_put: 2, meili_get: 1, meili_delete: 1]
|
||||
|
||||
def run(["index"]) do
|
||||
start_pleroma()
|
||||
|
@ -109,7 +109,7 @@ def run(["index"]) do
|
|||
def run(["clear"]) do
|
||||
start_pleroma()
|
||||
|
||||
meili_delete!("/indexes/objects/documents")
|
||||
meili_delete("/indexes/objects/documents")
|
||||
end
|
||||
|
||||
def run(["show-keys", master_key]) do
|
||||
|
|
|
@ -62,10 +62,9 @@ def meili_put(path, params) do
|
|||
end
|
||||
end
|
||||
|
||||
def meili_delete!(path) do
|
||||
def meili_delete(path) do
|
||||
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
||||
|
||||
{:ok, _} =
|
||||
Pleroma.HTTP.request(
|
||||
:delete,
|
||||
Path.join(endpoint, path),
|
||||
|
@ -155,16 +154,22 @@ def add_to_index(activity) do
|
|||
|
||||
with {:ok, res} <- result,
|
||||
true <- Map.has_key?(res, "uid") do
|
||||
# Do nothing
|
||||
# Added successfully
|
||||
:ok
|
||||
else
|
||||
_ ->
|
||||
# There was an error, report it
|
||||
Logger.error("Failed to add activity #{activity.id} to index: #{inspect(result)}")
|
||||
{:error, result}
|
||||
end
|
||||
else
|
||||
# The post isn't something we can search, that's ok
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def remove_from_index(object) do
|
||||
meili_delete!("/indexes/objects/documents/#{object.id}")
|
||||
meili_delete("/indexes/objects/documents/#{object.id}")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,8 +9,6 @@ def perform(%Job{args: %{"op" => "add_to_index", "activity" => activity_id}}) do
|
|||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||
|
||||
search_module.add_to_index(activity)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
def perform(%Job{args: %{"op" => "remove_from_index", "object" => object_id}}) do
|
||||
|
@ -19,7 +17,5 @@ def perform(%Job{args: %{"op" => "remove_from_index", "object" => object_id}}) d
|
|||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||
|
||||
search_module.remove_from_index(object)
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue