FrontendStatic: make Router a runtime dep
authorAlex Gleason <alex@alexgleason.me>
Fri, 21 May 2021 22:37:34 +0000 (17:37 -0500)
committerAlex Gleason <alex@alexgleason.me>
Sun, 30 May 2021 17:12:16 +0000 (12:12 -0500)
Speeds up recompilation by removing compile-time cycles

lib/pleroma/web/plugs/frontend_static.ex

index e7c943b41375765562c8d25b4dee7af0518fe995..ebe7eaf86bbdac1b55e58c36a9532bc8a2d30d0a 100644 (file)
@@ -10,8 +10,6 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
   """
   @behaviour Plug
 
-  @api_routes Pleroma.Web.Router.get_api_routes()
-
   def file_path(path, frontend_type \\ :primary) do
     if configuration = Pleroma.Config.get([:frontends, frontend_type]) do
       instance_static_path = Pleroma.Config.get([:instance, :static_dir], "instance/static")
@@ -55,10 +53,13 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
   defp invalid_path?([h | t], match), do: String.contains?(h, match) or invalid_path?(t)
   defp invalid_path?([], _match), do: false
 
-  defp api_route?([h | _]) when h in @api_routes, do: true
-  defp api_route?([_ | t]), do: api_route?(t)
   defp api_route?([]), do: false
 
+  defp api_route?([h | t]) do
+    api_routes = Pleroma.Web.Router.get_api_routes()
+    if h in api_routes, do: true, else: api_route?(t)
+  end
+
   defp call_static(conn, opts, from) do
     opts = Map.put(opts, :from, from)
     Plug.Static.call(conn, opts)