From b12d17d2ce270e0d964f599efd4f16fba95b17ce Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Wed, 18 Jul 2018 13:36:20 +0900 Subject: [PATCH] configurable timeout --- config/config.exs | 3 ++- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 5 +++-- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config/config.exs b/config/config.exs index c0a75b786..8fb7b7c22 100644 --- a/config/config.exs +++ b/config/config.exs @@ -98,7 +98,8 @@ config :pleroma, :gopher, config :pleroma, :suggestions, enabled: false, third_party_engine: - "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}" + "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}", + timeout: 300_000 # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 5b79f9600..396f11a70 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1077,7 +1077,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def suggestions(%{assigns: %{user: user}} = conn, _) do if Keyword.get(@suggestions, :enabled, false) do - api = Keyword.get(@suggestions, :third_party_engine, false) + api = Keyword.get(@suggestions, :third_party_engine, "") + timeout = Keyword.get(@suggestions, :timeout, 5000) host = Application.get_env(:pleroma, Pleroma.Web.Endpoint) @@ -1088,7 +1089,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) with {:ok, %{status_code: 200, body: body}} <- - @httpoison.get(url, [], timeout: 300_000, recv_timeout: 300_000), + @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout), {:ok, data} <- Jason.decode(body) do data2 = Enum.slice(data, 0, 40) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index e80e63f27..42d322f89 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -45,8 +45,11 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do metadata: %{ nodeName: Keyword.get(instance, :name), mediaProxy: Keyword.get(media_proxy, :enabled), - suggestions: Keyword.get(suggestions, :enabled, false), - suggestionsThirdPartyEngine: Keyword.get(suggestions, :third_party_engine, false) + suggestions: %{ + enabled: Keyword.get(suggestions, :enabled, false), + thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""), + timeout: Keyword.get(suggestions, :timeout, 5000) + } } } -- 2.45.2