From: FloatingGhost Date: Thu, 16 Dec 2021 15:58:56 +0000 (+0000) Subject: add timestamp X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=2152832780d7bb67b6d98ddf3714058bac2c03f4;p=akkoma add timestamp --- diff --git a/lib/pleroma/elasticsearch/document_mappings/hashtag.ex b/lib/pleroma/elasticsearch/document_mappings/hashtag.ex index 1c47d1451..ddf91231c 100644 --- a/lib/pleroma/elasticsearch/document_mappings/hashtag.ex +++ b/lib/pleroma/elasticsearch/document_mappings/hashtag.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Elasticsearch.DocumentMappings.Hashtag do def encode(hashtag) do %{ hashtag: hashtag.name, - timestamp: hashtag.inserted_at + timestamp: hashtag.timestamp } end end diff --git a/lib/pleroma/elasticsearch/store.ex b/lib/pleroma/elasticsearch/store.ex index 0860a5ee5..5c9e15022 100644 --- a/lib/pleroma/elasticsearch/store.ex +++ b/lib/pleroma/elasticsearch/store.ex @@ -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,12 +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 = data @@ -120,7 +127,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 -> diff --git a/lib/pleroma/hashtag.ex b/lib/pleroma/hashtag.ex index cdbfeab02..53e2e9c89 100644 --- a/lib/pleroma/hashtag.ex +++ b/lib/pleroma/hashtag.ex @@ -61,7 +61,6 @@ defmodule Pleroma.Hashtag do {:ok, Repo.all(from(ht in Hashtag, where: ht.name in ^names))} end) |> Repo.transaction() do - Pleroma.Elasticsearch.maybe_bulk_post(hashtags, :hashtags) {:ok, hashtags} else {:error, _name, value, _changes_so_far} -> {:error, value}