forked from AkkomaGang/akkoma
add timestamp
This commit is contained in:
parent
1745606ab5
commit
2152832780
3 changed files with 15 additions and 9 deletions
|
@ -4,7 +4,7 @@ def id(obj), do: obj.id
|
||||||
def encode(hashtag) do
|
def encode(hashtag) do
|
||||||
%{
|
%{
|
||||||
hashtag: hashtag.name,
|
hashtag: hashtag.name,
|
||||||
timestamp: hashtag.inserted_at
|
timestamp: hashtag.timestamp
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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,12 +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 =
|
||||||
data
|
data
|
||||||
|
@ -120,7 +127,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 ->
|
||||||
|
|
|
@ -61,7 +61,6 @@ def get_or_create_by_names(names) when is_list(names) do
|
||||||
{:ok, Repo.all(from(ht in Hashtag, where: ht.name in ^names))}
|
{:ok, Repo.all(from(ht in Hashtag, where: ht.name in ^names))}
|
||||||
end)
|
end)
|
||||||
|> Repo.transaction() do
|
|> Repo.transaction() do
|
||||||
Pleroma.Elasticsearch.maybe_bulk_post(hashtags, :hashtags)
|
|
||||||
{:ok, hashtags}
|
{:ok, hashtags}
|
||||||
else
|
else
|
||||||
{:error, _name, value, _changes_so_far} -> {:error, value}
|
{:error, _name, value, _changes_so_far} -> {:error, value}
|
||||||
|
|
Loading…
Reference in a new issue