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)
1  2 
lib/pleroma/elasticsearch/store.ex

index aa5e2b1040689e29944ac93255d0080cf1ba9d3e,5c9e1502210b28915d835f2878df794072e055cb..7f6ef37a927ad46dcbbbe4e36761c5b66e1b0e54
@@@ -1,6 -1,7 +1,7 @@@
  defmodule Pleroma.Elasticsearch do
    alias Pleroma.Activity
    alias Pleroma.User
+   alias Pleroma.Object
    alias Pleroma.Elasticsearch.DocumentMappings
    alias Pleroma.Config
    require Logger
      {: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(
          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
        )
    end
  
-   def maybe_bulk_post(data, type) do
-     if enabled?() do
-       bulk_post(data, type)
-     end
-   end
 +
    def bulk_post(data, :users) do
      d =
        data
 +      |> Enum.filter(fn x -> x.actor_type == "Person" end)
        |> Enum.map(fn d ->
          [
            %{index: %{_id: DocumentMappings.User.id(d)}},
      )
    end
  
-   def bulk_post([] = data, :hashtags) do
+   def bulk_post(data, :hashtags) when is_list(data) do
      d =
        data
        |> Enum.map(fn d ->