Merge branch 'develop' into stable
[akkoma] / lib / mix / tasks / pleroma / search.ex
index 9e0f376c38957a2c3042fb15b45196b9edabb07e..102bc5b63bed69fd7fcdd0b73c2e038948ed3687 100644 (file)
@@ -5,42 +5,16 @@
 defmodule Mix.Tasks.Pleroma.Search do
   use Mix.Task
   import Mix.Pleroma
-  import Ecto.Query
-  alias Pleroma.Activity
-  alias Pleroma.Pagination
 
   @shortdoc "Manages elasticsearch"
 
-  def run(["import" | _rest]) do
+  def run(["import", "activities" | _rest]) do
     start_pleroma()
 
-    from(a in Activity, where: not ilike(a.actor, "%/relay"))
-    |> Activity.with_preloaded_object()
-    |> Activity.with_preloaded_user_actor()
-    |> get_all
-  end
-
-  defp get_all(query, max_id \\ nil) do
-    params = %{limit: 20}
-
-    params =
-      if max_id == nil do
-        params
-      else
-        Map.put(params, :max_id, max_id)
-      end
-
-    res =
-      query
-      |> Pagination.fetch_paginated(params)
-
-    if res == [] do
-      :ok
-    else
-      res
-      |> Pleroma.Elasticsearch.bulk_post(:activities)
-
-      get_all(query, List.last(res).id)
-    end
+    Elasticsearch.Index.Bulk.upload(
+      Pleroma.Search.Elasticsearch.Cluster,
+      "activities",
+      Pleroma.Config.get([Pleroma.Search.Elasticsearch.Cluster, :indexes, :activities])
+    )
   end
 end