fetcher: more descriptive variable names

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-06-14 22:24:00 +02:00
parent 4644a8bd10
commit 6b9c4bc1f1
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE

View File

@ -23,21 +23,21 @@ defmodule Pleroma.Object.Fetcher do
Ecto.Changeset.put_change(changeset, :updated_at, updated_at) Ecto.Changeset.put_change(changeset, :updated_at, updated_at)
end end
defp maybe_reinject_internal_fields(data, %{data: %{} = old_data}) do defp maybe_reinject_internal_fields(%{data: %{} = old_data}, new_data) do
internal_fields = Map.take(old_data, Pleroma.Constants.object_internal_fields()) internal_fields = Map.take(old_data, Pleroma.Constants.object_internal_fields())
Map.merge(data, internal_fields) Map.merge(new_data, internal_fields)
end end
defp maybe_reinject_internal_fields(data, _), do: data defp maybe_reinject_internal_fields(_, new_data), do: new_data
@spec reinject_object(struct(), map()) :: {:ok, Object.t()} | {:error, any()} @spec reinject_object(struct(), map()) :: {:ok, Object.t()} | {:error, any()}
defp reinject_object(struct, data) do defp reinject_object(%Object{} = object, new_data) do
Logger.debug("Reinjecting object #{data["id"]}") Logger.debug("Reinjecting object #{new_data["id"]}")
with data <- Transmogrifier.fix_object(data), with new_data <- Transmogrifier.fix_object(new_data),
data <- maybe_reinject_internal_fields(data, struct), data <- maybe_reinject_internal_fields(object, new_data),
changeset <- Object.change(struct, %{data: data}), changeset <- Object.change(object, %{data: data}),
changeset <- touch_changeset(changeset), changeset <- touch_changeset(changeset),
{:ok, object} <- Repo.insert_or_update(changeset), {:ok, object} <- Repo.insert_or_update(changeset),
{:ok, object} <- Object.set_cache(object) do {:ok, object} <- Object.set_cache(object) do
@ -51,8 +51,8 @@ defmodule Pleroma.Object.Fetcher do
def refetch_object(%Object{data: %{"id" => id}} = object) do def refetch_object(%Object{data: %{"id" => id}} = object) do
with {:local, false} <- {:local, Object.local?(object)}, with {:local, false} <- {:local, Object.local?(object)},
{:ok, data} <- fetch_and_contain_remote_object_from_id(id), {:ok, new_data} <- fetch_and_contain_remote_object_from_id(id),
{:ok, object} <- reinject_object(object, data) do {:ok, object} <- reinject_object(object, new_data) do
{:ok, object} {:ok, object}
else else
{:local, true} -> {:ok, object} {:local, true} -> {:ok, object}