Merge branch 'handle-search-timeout' into 'develop'
Handle search timeouts for /api/v1/search and /api/v2/search Closes #994 See merge request pleroma/pleroma!1369
This commit is contained in:
commit
079266d406
|
@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Not being able to pin unlisted posts
|
- Not being able to pin unlisted posts
|
||||||
|
- Mastodon API: Handling of search timeouts (`/api/v1/search` and `/api/v2/search`)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
||||||
|
|
|
@ -17,8 +17,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
||||||
plug(Pleroma.Plugs.RateLimiter, :search when action in [:search, :search2, :account_search])
|
plug(Pleroma.Plugs.RateLimiter, :search when action in [:search, :search2, :account_search])
|
||||||
|
|
||||||
def search2(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
|
def search2(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
|
||||||
accounts = User.search(query, search_options(params, user))
|
accounts = with_fallback(fn -> User.search(query, search_options(params, user)) end, [])
|
||||||
statuses = Activity.search(user, query)
|
statuses = with_fallback(fn -> Activity.search(user, query) end, [])
|
||||||
tags_path = Web.base_url() <> "/tag/"
|
tags_path = Web.base_url() <> "/tag/"
|
||||||
|
|
||||||
tags =
|
tags =
|
||||||
|
@ -40,8 +40,8 @@ def search2(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
|
def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
|
||||||
accounts = User.search(query, search_options(params, user))
|
accounts = with_fallback(fn -> User.search(query, search_options(params, user)) end, [])
|
||||||
statuses = Activity.search(user, query)
|
statuses = with_fallback(fn -> Activity.search(user, query) end, [])
|
||||||
|
|
||||||
tags =
|
tags =
|
||||||
query
|
query
|
||||||
|
@ -76,4 +76,14 @@ defp search_options(params, user) do
|
||||||
for_user: user
|
for_user: user
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp with_fallback(f, fallback) do
|
||||||
|
try do
|
||||||
|
f.()
|
||||||
|
rescue
|
||||||
|
error ->
|
||||||
|
Logger.error("#{__MODULE__} search error: #{inspect(error)}")
|
||||||
|
fallback
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue