From 66d8d670e0f52c684e68ab556059c0bf409e727e Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 21 Sep 2020 23:34:33 +0300 Subject: tmp --- lib/pleroma/object/fetcher.ex | 19 ++++++----- lib/pleroma/web/fed_sockets/socket_info.ex | 52 ------------------------------ 2 files changed, 11 insertions(+), 60 deletions(-) delete mode 100644 lib/pleroma/web/fed_sockets/socket_info.ex diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index 9468087cb..e5e5f8db7 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -211,14 +211,17 @@ defmodule Pleroma.Object.Fetcher do do: {:error, "id must be a string"} defp get_object(id, opts) do - with false <- Keyword.get(opts, :force_http, false) do - Logger.debug("fetching via fedsocket - #{inspect(id)}") - FedSockets.fetch(id) - else - _other -> - Logger.debug("fetching via http - #{inspect(id)}") - get_object_http(id) - end + with false <- Keyword.get(opts, :force_http, false), + _ <- Logger.debug("fetching via fedsocket - #{inspect(id)}") + + {:ok, data} <- + FedSockets.fetch id do + {:ok, data} + else + _other -> + Logger.debug("fetching via http - #{inspect(id)}") + get_object_http(id) + end end defp get_object_http(id) do diff --git a/lib/pleroma/web/fed_sockets/socket_info.ex b/lib/pleroma/web/fed_sockets/socket_info.ex deleted file mode 100644 index d6fdffe1a..000000000 --- a/lib/pleroma/web/fed_sockets/socket_info.ex +++ /dev/null @@ -1,52 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.FedSockets.SocketInfo do - defstruct origin: nil, - pid: nil, - conn_pid: nil, - state: :default, - connected_until: nil - - alias Pleroma.Web.FedSockets.SocketInfo - @default_connection_duration 15 * 60 * 1000 - - def build(uri, conn_pid \\ nil) do - uri - |> build_origin() - |> build_pids(conn_pid) - |> touch() - end - - def touch(%SocketInfo{} = socket_info), - do: %{socket_info | connected_until: new_ttl()} - - def connect(%SocketInfo{} = socket_info), - do: %{socket_info | state: :connected} - - def expired?(%{connected_until: connected_until}), - do: connected_until < :erlang.monotonic_time(:millisecond) - - def origin(uri), - do: build_origin(uri).origin - - defp build_pids(socket_info, conn_pid), - do: struct(socket_info, pid: self(), conn_pid: conn_pid) - - defp build_origin(uri) when is_binary(uri), - do: uri |> URI.parse() |> build_origin - - defp build_origin(%{host: host, port: nil, scheme: scheme}), - do: build_origin(%{host: host, port: URI.default_port(scheme)}) - - defp build_origin(%{host: host, port: port}), - do: %SocketInfo{origin: "#{host}:#{port}"} - - defp new_ttl do - connection_duration = - Pleroma.Config.get([:fed_sockets, :connection_duration], @default_connection_duration) - - :erlang.monotonic_time(:millisecond) + connection_duration - end -end -- cgit v1.2.3