Merge branch 'develop' into stable
[akkoma] / lib / mix / tasks / pleroma / search.ex
index 4acd0e34ac7fcf4e7cc74c3e1b745fbe4ea11eb0..102bc5b63bed69fd7fcdd0b73c2e038948ed3687 100644 (file)
@@ -5,42 +5,16 @@
 defmodule Mix.Tasks.Pleroma.Search do
   use Mix.Task
   import Mix.Pleroma
-  import Ecto.Query
-  alias Pleroma.Elasticsearch
-  alias Pleroma.Activity
-  alias Pleroma.Repo
-  alias Pleroma.Pagination
 
   @shortdoc "Manages elasticsearch"
 
-  def run(["import" | rest]) do
+  def run(["import", "activities" | _rest]) do
     start_pleroma()
 
-    query = from(a in Activity, where: not ilike(a.actor, "%/relay"))
-    |> Activity.with_preloaded_object
-    |> Activity.with_preloaded_user_actor
-    |> get_all
+    Elasticsearch.Index.Bulk.upload(
+      Pleroma.Search.Elasticsearch.Cluster,
+      "activities",
+      Pleroma.Config.get([Pleroma.Search.Elasticsearch.Cluster, :indexes, :activities])
+    )
   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
-  end
-
 end