From: Maksim Pechnikov Date: Sun, 16 Aug 2020 03:54:48 +0000 (+0300) Subject: fix search media proxy urls X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=f6da12f45d98707ad5e106e56cf36c055c3e105d;p=akkoma fix search media proxy urls --- diff --git a/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex b/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex index 76d3af4ef..131e22d78 100644 --- a/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex @@ -38,18 +38,20 @@ 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 - end + defp filter_entries(stream, query) when is_binary(query) do + regex = ~r/#{query}/i - defp filter_urls(entries, _) do - Enum.map(entries, fn {_, url, _, _, _} -> url end) + stream + |> Enum.filter(fn url -> String.match?(url, regex) end) + |> Enum.to_list() end + defp filter_entries(stream, _), do: Enum.to_list(stream) + defp paginate_entries(entries, page, page_size) do offset = page_size * (page - 1) Enum.slice(entries, offset, page_size) diff --git a/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs b/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs index 3cf98d7c7..f243d1fb2 100644 --- a/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs +++ b/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs @@ -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"] == [