Merge remote-tracking branch 'origin/feature/elasticsearch' into develop
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Thu, 16 Dec 2021 16:13:41 +0000 (16:13 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Thu, 16 Dec 2021 16:13:41 +0000 (16:13 +0000)
lib/mix/tasks/pleroma/activity.ex
lib/pleroma/elasticsearch/document_mappings/hashtag.ex
lib/pleroma/elasticsearch/store.ex

index 53323efd647ef752e9e0f1f91dec0e2dd9904aad..3a79d8f206ded11728c788b1f051b2f26ba6c5bd 100644 (file)
@@ -4,19 +4,13 @@
 
 defmodule Mix.Tasks.Pleroma.Activity do
   alias Pleroma.Activity
-  alias Pleroma.Activity.Search
   alias Pleroma.User
   alias Pleroma.Web.CommonAPI
   alias Pleroma.Pagination
   require Logger
   import Mix.Pleroma
   import Ecto.Query
-  @shortdoc "A collection of activity debug tasks"
-  @moduledoc """
-   A collection of activity related tasks
 
-   mix pleroma.activity get <id>
-  """
   def run(["get", id | _rest]) do
     start_pleroma()
 
index 1c47d1451d522e57ded33ca98886e531d593eb11..ce9a86c8d07edf4f61c044f98dff87b3a46675d7 100644 (file)
@@ -1,6 +1,13 @@
 defmodule Pleroma.Elasticsearch.DocumentMappings.Hashtag do
   def id(obj), do: obj.id
 
+  def encode(%{timestamp: _} = hashtag) do
+    %{
+      hashtag: hashtag.name,
+      timestamp: hashtag.timestamp
+    }
+  end
+
   def encode(hashtag) do
     %{
       hashtag: hashtag.name,
index aa5e2b1040689e29944ac93255d0080cf1ba9d3e..7f6ef37a927ad46dcbbbe4e36761c5b66e1b0e54 100644 (file)
@@ -1,6 +1,7 @@
 defmodule Pleroma.Elasticsearch do
   alias Pleroma.Activity
   alias Pleroma.User
+  alias Pleroma.Object
   alias Pleroma.Elasticsearch.DocumentMappings
   alias Pleroma.Config
   require Logger
@@ -45,6 +46,12 @@ defmodule Pleroma.Elasticsearch do
     {:ok, :skipped}
   end
 
+  def maybe_bulk_post(data, type) do
+    if enabled?() do
+      bulk_post(data, type)
+    end
+  end
+
   def put(%Activity{} = activity) do
     {:ok, _} =
       Elastix.Document.index(
@@ -54,6 +61,12 @@ defmodule Pleroma.Elasticsearch do
         DocumentMappings.Activity.id(activity),
         DocumentMappings.Activity.encode(activity)
       )
+
+    activity
+    |> Map.get(:object)
+    |> Object.hashtags()
+    |> Enum.map(fn x -> %{id: x, name: x, timestamp: DateTime.to_iso8601(DateTime.utc_now())} end)
+    |> bulk_post(:hashtags)
   end
 
   def put(%User{} = user) do
@@ -95,11 +108,6 @@ defmodule Pleroma.Elasticsearch do
       )
   end
 
-  def maybe_bulk_post(data, type) do
-    if enabled?() do
-      bulk_post(data, type)
-    end
-  end
 
   def bulk_post(data, :users) do
     d =
@@ -121,7 +129,7 @@ defmodule Pleroma.Elasticsearch do
     )
   end
 
-  def bulk_post([] = data, :hashtags) do
+  def bulk_post(data, :hashtags) when is_list(data) do
     d =
       data
       |> Enum.map(fn d ->