fix ES import from live (#29)
authorfloatingghost <hannah@coffee-and-dreams.uk>
Thu, 30 Jun 2022 18:44:31 +0000 (18:44 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Thu, 30 Jun 2022 18:44:31 +0000 (18:44 +0000)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/29

config/config.exs
docs/configuration/search.md
lib/mix/pleroma.ex
lib/mix/tasks/pleroma/search.ex [new file with mode: 0644]
lib/mix/tasks/pleroma/search/elasticsearch.ex [deleted file]

index 727a2b0cb5b6b886d3e045bbd3bd93275ce47a63..b00fd18e3be097b9e157f0f20eb80dd7c7b99ccd 100644 (file)
@@ -874,7 +874,7 @@ config :pleroma, Pleroma.Search.Elasticsearch.Cluster,
       settings: "priv/es-mappings/activity.json",
       store: Pleroma.Search.Elasticsearch.Store,
       sources: [Pleroma.Activity],
-      bulk_page_size: 5000,
+      bulk_page_size: 1000,
       bulk_wait_interval: 15_000
     }
   }
index 7c1093ab9c2d9828cb30debe69fa7f0c18f96a03..e1f23b505d1f28f5516b8dd1c3db63204887927e 100644 (file)
@@ -154,10 +154,10 @@ To start the initial indexing, run the `build` command:
 
 === "OTP"
 ```sh
-./bin/pleroma_ctl search.elasticsearch index activities --cluster Pleroma.Search.Elasticsearch.Cluster
+./bin/pleroma_ctl search import activities
 ```
 
 === "From Source"
 ```sh
-mix elasticsearch.build activities --cluster Pleroma.Search.Elasticsearch.Cluster
-```
\ No newline at end of file
+mix pleroma.search import activities
+```
index 2b6c7d6bbd13f364fefa396e66a778d6b480f2d6..02c40850a7430b7c4c0b74463df007c08b57cc64 100644 (file)
@@ -57,7 +57,8 @@ defmodule Mix.Pleroma do
         {Majic.Pool,
          [name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]}
       ] ++
-        http_children(adapter)
+        http_children(adapter) ++
+        elasticsearch_children()
 
     cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
 
@@ -136,4 +137,14 @@ defmodule Mix.Pleroma do
   end
 
   defp http_children(_), do: []
+
+  def elasticsearch_children do
+    config = Pleroma.Config.get([Pleroma.Search, :module])
+
+    if config == Pleroma.Search.Elasticsearch do
+      [Pleroma.Search.Elasticsearch.Cluster]
+    else
+      []
+    end
+  end
 end
diff --git a/lib/mix/tasks/pleroma/search.ex b/lib/mix/tasks/pleroma/search.ex
new file mode 100644 (file)
index 0000000..102bc5b
--- /dev/null
@@ -0,0 +1,20 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.Search do
+  use Mix.Task
+  import Mix.Pleroma
+
+  @shortdoc "Manages elasticsearch"
+
+  def run(["import", "activities" | _rest]) do
+    start_pleroma()
+
+    Elasticsearch.Index.Bulk.upload(
+      Pleroma.Search.Elasticsearch.Cluster,
+      "activities",
+      Pleroma.Config.get([Pleroma.Search.Elasticsearch.Cluster, :indexes, :activities])
+    )
+  end
+end
diff --git a/lib/mix/tasks/pleroma/search/elasticsearch.ex b/lib/mix/tasks/pleroma/search/elasticsearch.ex
deleted file mode 100644 (file)
index 1d7d7a2..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-defmodule Mix.Tasks.Pleroma.Search.Elasticsearch do
-  alias Mix.Tasks.Elasticsearch.Build
-  import Mix.Pleroma
-
-  def run(["index" | args]) do
-    start_pleroma()
-    Build.run(args)
-  end
-end