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 Ecto.Query
|
||||||
|
|
||||||
import Pleroma.Search.Meilisearch,
|
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
|
def run(["index"]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
@ -109,7 +109,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
|
|||||||
def run(["clear"]) do
|
def run(["clear"]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
meili_delete!("/indexes/objects/documents")
|
meili_delete("/indexes/objects/documents")
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["show-keys", master_key]) do
|
def run(["show-keys", master_key]) do
|
||||||
|
@ -62,10 +62,9 @@ defmodule Pleroma.Search.Meilisearch do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def meili_delete!(path) do
|
def meili_delete(path) do
|
||||||
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
endpoint = Pleroma.Config.get([Pleroma.Search.Meilisearch, :url])
|
||||||
|
|
||||||
{:ok, _} =
|
|
||||||
Pleroma.HTTP.request(
|
Pleroma.HTTP.request(
|
||||||
:delete,
|
:delete,
|
||||||
Path.join(endpoint, path),
|
Path.join(endpoint, path),
|
||||||
@ -155,16 +154,22 @@ defmodule Pleroma.Search.Meilisearch do
|
|||||||
|
|
||||||
with {:ok, res} <- result,
|
with {:ok, res} <- result,
|
||||||
true <- Map.has_key?(res, "uid") do
|
true <- Map.has_key?(res, "uid") do
|
||||||
# Do nothing
|
# Added successfully
|
||||||
|
:ok
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
|
# There was an error, report it
|
||||||
Logger.error("Failed to add activity #{activity.id} to index: #{inspect(result)}")
|
Logger.error("Failed to add activity #{activity.id} to index: #{inspect(result)}")
|
||||||
|
{:error, result}
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
# The post isn't something we can search, that's ok
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def remove_from_index(object) do
|
def remove_from_index(object) do
|
||||||
meili_delete!("/indexes/objects/documents/#{object.id}")
|
meili_delete("/indexes/objects/documents/#{object.id}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,8 +9,6 @@ defmodule Pleroma.Workers.SearchIndexingWorker do
|
|||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||||
|
|
||||||
search_module.add_to_index(activity)
|
search_module.add_to_index(activity)
|
||||||
|
|
||||||
: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
|
||||||
@ -19,7 +17,5 @@ defmodule Pleroma.Workers.SearchIndexingWorker do
|
|||||||
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
search_module = Pleroma.Config.get([Pleroma.Search, :module])
|
||||||
|
|
||||||
search_module.remove_from_index(object)
|
search_module.remove_from_index(object)
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user