Skip to content

Commit

Permalink
chore: remove unused alert caching code (#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
sloanelybutsurely authored Aug 28, 2024
1 parent 761f360 commit 0180877
Show file tree
Hide file tree
Showing 18 changed files with 7 additions and 751 deletions.
3 changes: 0 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,6 @@ config :screens, Screens.ScreenApiResponseCache,
gc_interval: :timer.hours(1),
allocated_memory: 250_000_000

config :screens, Screens.Stops.StopsToRoutes, adapter: Nebulex.Adapters.Local
config :screens, Screens.Routes.RoutesCache, adapter: Nebulex.Adapters.Local

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
5 changes: 0 additions & 5 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ config :screens,
blue_bikes_station_information_url: [:no_api_requests_allowed_during_testing],
blue_bikes_station_status_url: [:no_api_requests_allowed_during_testing],
blue_bikes_api_client: Screens.BlueBikes.FakeClient,
stops_to_routes_route_mod: Screens.Routes.Route.Mock,
routes_cache_route_mod: Screens.Routes.Route.Mock,
dup_headsign_replacements: %{
"Test 1" => "T1"
},
Expand Down Expand Up @@ -162,6 +160,3 @@ config :screens, :screens_by_alert,
screens_by_alert_ttl_seconds: 2,
screens_last_updated_ttl_seconds: 2,
screens_ttl_seconds: 1

config :screens, Screens.Stops.StopsToRoutes, adapter: Nebulex.Adapters.Nil
config :screens, Screens.Routes.RoutesCache, adapter: Nebulex.Adapters.Nil
45 changes: 1 addition & 44 deletions lib/screens/alerts/alert.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
defmodule Screens.Alerts.Alert do
@moduledoc false

import Screens.RouteType, only: :macros

alias Screens.Alerts.Cache
alias Screens.Alerts.InformedEntity
alias Screens.Routes.Route
alias Screens.RouteType
Expand Down Expand Up @@ -192,46 +189,6 @@ defmodule Screens.Alerts.Alert do
end)
end

def fetch_from_cache(filters \\ [], get_all_alerts \\ &Cache.all/0) do
alerts = get_all_alerts.()

filters =
filters
|> Enum.map(&format_cache_filter/1)
|> Enum.reject(&is_nil/1)
|> Enum.into(%{})

{:ok, Screens.Alerts.Cache.Filter.filter_by(alerts, filters)}
end

def fetch_from_cache_or_empty_list(filters \\ [], get_all_alerts \\ &Cache.all/0) do
{:ok, alerts} = fetch_from_cache(filters, get_all_alerts)

alerts
end

defp format_cache_filter({:route_id, route_id}), do: {:routes, [route_id]}
defp format_cache_filter({:stop_id, stop_id}), do: {:stops, [stop_id]}
defp format_cache_filter({:route_ids, route_ids}), do: {:routes, route_ids}
defp format_cache_filter({:stop_ids, stop_ids}), do: {:stops, stop_ids}

defp format_cache_filter({:route_type, route_type}),
do: format_cache_filter({:route_types, [route_type]})

defp format_cache_filter({:route_types, route_types}) do
route_types =
Enum.map(route_types, fn
route_type when is_route_type(route_type) -> RouteType.to_id(route_type)
route_type -> route_type
end)

{:route_types, route_types}
end

defp format_cache_filter({:direction_id, :both}), do: nil

defp format_cache_filter(filter), do: filter

@doc """
Convenience for cases when it's safe to treat an API alert data outage
as if there simply aren't any alerts for the given parameters.
Expand Down Expand Up @@ -565,7 +522,7 @@ defmodule Screens.Alerts.Alert do
def by_route_id(route_id, stop_id) do
{inline_alerts, global_alerts} =
[route_id: route_id]
|> fetch_from_cache_or_empty_list()
|> fetch_or_empty_list()
|> Enum.split_with(&inline?/1)

global_alert = Enum.min_by(global_alerts, &sort_key(&1, stop_id), fn -> nil end)
Expand Down
82 changes: 0 additions & 82 deletions lib/screens/alerts/cache.ex

This file was deleted.

188 changes: 0 additions & 188 deletions lib/screens/alerts/cache/filter.ex

This file was deleted.

5 changes: 1 addition & 4 deletions lib/screens/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ defmodule Screens.Application do
{Screens.ScreensByAlert.SelfRefreshRunner, name: Screens.ScreensByAlert.SelfRefreshRunner},
Screens.OlCrowding.DynamicSupervisor,
{Screens.OlCrowding.Agent, %{}},
{Screens.ScreenApiResponseCache, []},
Screens.Streams.Alerts,
Screens.Stops.StopsToRoutes,
Screens.Routes.RoutesCache
{Screens.ScreenApiResponseCache, []}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
3 changes: 1 addition & 2 deletions lib/screens/routes/route.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ defmodule Screens.Routes.Route do
@type color :: name_colors() | :purple | :teal | :yellow
@type icon :: name_colors() | :bus | :cr | :ferry | :mattapan

@callback by_id(id()) :: {:ok, t()} | :error
@spec by_id(id()) :: {:ok, t()} | :error
def by_id(route_id) do
case V3Api.get_json("routes/" <> route_id) do
Expand All @@ -63,7 +62,7 @@ defmodule Screens.Routes.Route do
end

@doc "Fetches routes that serve the given stop."
@callback serving_stop(Stop.id()) :: {:ok, [t()]} | :error
@spec serving_stop(Stop.id()) :: {:ok, [t()]} | :error
def serving_stop(
stop_id,
get_json_fn \\ &V3Api.get_json/2,
Expand Down
Loading

0 comments on commit 0180877

Please sign in to comment.