Merge remote-tracking branch 'origin/feature/elasticsearch' into develop

This commit is contained in:
FloatingGhost 2021-12-16 16:13:41 +00:00
commit 415d9dd6f6
3 changed files with 21 additions and 12 deletions

View file

@ -4,19 +4,13 @@
defmodule Mix.Tasks.Pleroma.Activity do defmodule Mix.Tasks.Pleroma.Activity do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Activity.Search
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Pagination alias Pleroma.Pagination
require Logger require Logger
import Mix.Pleroma import Mix.Pleroma
import Ecto.Query 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 def run(["get", id | _rest]) do
start_pleroma() start_pleroma()

View file

@ -1,6 +1,13 @@
defmodule Pleroma.Elasticsearch.DocumentMappings.Hashtag do defmodule Pleroma.Elasticsearch.DocumentMappings.Hashtag do
def id(obj), do: obj.id def id(obj), do: obj.id
def encode(%{timestamp: _} = hashtag) do
%{
hashtag: hashtag.name,
timestamp: hashtag.timestamp
}
end
def encode(hashtag) do def encode(hashtag) do
%{ %{
hashtag: hashtag.name, hashtag: hashtag.name,

View file

@ -1,6 +1,7 @@
defmodule Pleroma.Elasticsearch do defmodule Pleroma.Elasticsearch do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.User alias Pleroma.User
alias Pleroma.Object
alias Pleroma.Elasticsearch.DocumentMappings alias Pleroma.Elasticsearch.DocumentMappings
alias Pleroma.Config alias Pleroma.Config
require Logger require Logger
@ -45,6 +46,12 @@ def maybe_put_into_elasticsearch(_) do
{:ok, :skipped} {:ok, :skipped}
end end
def maybe_bulk_post(data, type) do
if enabled?() do
bulk_post(data, type)
end
end
def put(%Activity{} = activity) do def put(%Activity{} = activity) do
{:ok, _} = {:ok, _} =
Elastix.Document.index( Elastix.Document.index(
@ -54,6 +61,12 @@ def put(%Activity{} = activity) do
DocumentMappings.Activity.id(activity), DocumentMappings.Activity.id(activity),
DocumentMappings.Activity.encode(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 end
def put(%User{} = user) do def put(%User{} = user) do
@ -95,11 +108,6 @@ def bulk_post(data, :activities) do
) )
end end
def maybe_bulk_post(data, type) do
if enabled?() do
bulk_post(data, type)
end
end
def bulk_post(data, :users) do def bulk_post(data, :users) do
d = d =
@ -121,7 +129,7 @@ def bulk_post(data, :users) do
) )
end end
def bulk_post([] = data, :hashtags) do def bulk_post(data, :hashtags) when is_list(data) do
d = d =
data data
|> Enum.map(fn d -> |> Enum.map(fn d ->