Skip to content

Commit 76c39fb

Browse files
authored
fix(perf): Store subway status in ETS, rather than a GenServer's state (#3296)
1 parent b4d22f7 commit 76c39fb

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

lib/dotcom/system_status/subway_cache.ex

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ defmodule Dotcom.SystemStatus.SubwayCache do
2121

2222
@impl Behaviour
2323
def subway_status() do
24-
GenServer.call(__MODULE__, :subway_status)
24+
:ets.lookup(:subway_status, "status")
25+
|> case do
26+
[{"status", status}] -> status
27+
_ -> status()
28+
end
2529
end
2630

2731
@impl Behaviour
@@ -35,19 +39,20 @@ defmodule Dotcom.SystemStatus.SubwayCache do
3539
def init(_opts) do
3640
Alerts.Cache.Store.subscribe()
3741

38-
{:ok, status()}
39-
end
42+
status = status()
4043

41-
@impl true
42-
def handle_call(:subway_status, _from, status) do
43-
{:reply, status, status}
44+
:ets.new(:subway_status, [:named_table, :set, :protected, read_concurrency: true])
45+
:ets.insert(:subway_status, {"status", status})
46+
47+
{:ok, status}
4448
end
4549

4650
@impl true
4751
def handle_info(%{event: "alerts_updated"}, old_status) do
4852
new_status = status()
4953

5054
if new_status != old_status do
55+
:ets.insert(:subway_status, {"status", new_status})
5156
DotcomWeb.Endpoint.broadcast(@pubsub_topic, "subway_status_updated", new_status)
5257
end
5358

0 commit comments

Comments
 (0)