Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
mkljczk committed Nov 25, 2024
2 parents 1f06b2a + d92d613 commit ffa874e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.d/meilisearch-misc-fixes.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Miscellaneous fixes for Meilisearch support
1 change: 1 addition & 0 deletions changelog.d/module-search-in-pleroma-ctl.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pleroma_ctl mix task calls sometimes not being found
6 changes: 3 additions & 3 deletions lib/mix/tasks/pleroma/search/meilisearch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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_put: 2, meili_get: 1, meili_delete: 1]

def run(["index"]) do
start_pleroma()
Expand All @@ -28,7 +28,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
end

{:ok, _} =
meili_post(
meili_put(
"/indexes/objects/settings/ranking-rules",
[
"published:desc",
Expand All @@ -42,7 +42,7 @@ defmodule Mix.Tasks.Pleroma.Search.Meilisearch do
)

{:ok, _} =
meili_post(
meili_put(
"/indexes/objects/settings/searchable-attributes",
[
"content"
Expand Down
23 changes: 15 additions & 8 deletions lib/pleroma/release_tasks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ defmodule Pleroma.ReleaseTasks do
end
end

def find_module(task) do
module_name =
task
|> String.split(".")
|> Enum.map(&String.capitalize/1)
|> then(fn x -> [Mix, Tasks, Pleroma] ++ x end)
|> Module.concat()

case Code.ensure_loaded(module_name) do
{:module, _} -> module_name
_ -> nil
end
end

defp mix_task(task, args) do
Application.load(:pleroma)
{:ok, modules} = :application.get_key(:pleroma, :modules)

module =
Enum.find(modules, fn module ->
module = Module.split(module)

match?(["Mix", "Tasks", "Pleroma" | _], module) and
String.downcase(List.last(module)) == task
end)
module = find_module(task)

if module do
module.run(args)
Expand Down
1 change: 1 addition & 0 deletions lib/pleroma/search/meilisearch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ defmodule Pleroma.Search.Meilisearch do
# Only index public or unlisted Notes
if not is_nil(object) and object.data["type"] == "Note" and
not is_nil(object.data["content"]) and
not is_nil(object.data["published"]) and
(Pleroma.Constants.as_public() in object.data["to"] or
Pleroma.Constants.as_public() in object.data["cc"]) and
object.data["content"] not in ["", "."] do
Expand Down
19 changes: 19 additions & 0 deletions test/pleroma/release_task_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.ReleaseTaskTest do
use Pleroma.DataCase, async: true

alias Pleroma.ReleaseTasks

test "finding the module" do
task = "search.meilisearch"
assert Mix.Tasks.Pleroma.Search.Meilisearch == ReleaseTasks.find_module(task)

task = "user"
assert Mix.Tasks.Pleroma.User == ReleaseTasks.find_module(task)

refute ReleaseTasks.find_module("doesnt.exist")
end
end

0 comments on commit ffa874e

Please sign in to comment.