fix search media proxy urls

This commit is contained in:
Maksim Pechnikov 2020-08-16 06:54:48 +03:00
parent 56470647de
commit f6da12f45d
2 changed files with 10 additions and 8 deletions

View File

@ -38,17 +38,19 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheController do
defp fetch_entries(params) do
MediaProxy.cache_table()
|> Cachex.export!()
|> filter_urls(params[:query])
|> Cachex.stream!(Cachex.Query.create(true, :key))
|> filter_entries(params[:query])
end
defp filter_urls(entries, query) when is_binary(query) do
for {_, url, _, _, _} <- entries, String.contains?(url, query), do: url
defp filter_entries(stream, query) when is_binary(query) do
regex = ~r/#{query}/i
stream
|> Enum.filter(fn url -> String.match?(url, regex) end)
|> Enum.to_list()
end
defp filter_urls(entries, _) do
Enum.map(entries, fn {_, url, _, _, _} -> url end)
end
defp filter_entries(stream, _), do: Enum.to_list(stream)
defp paginate_entries(entries, page, page_size) do
offset = page_size * (page - 1)

View File

@ -89,7 +89,7 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
response =
conn
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&query=f44")
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&query=F44")
|> json_response_and_validate_schema(200)
assert response["urls"] == [