fix: handle missing :pending_batch_tasks assign in historical loader
Use Map.get with default for all loading_generation and pending_batch_tasks socket.assigns accesses to prevent KeyError when key is not present.
This commit is contained in:
parent
d63cdf4cda
commit
b93d4904a3
1 changed files with 2 additions and 2 deletions
|
|
@ -113,7 +113,7 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
|
|||
@spec cancel_pending_loads(Socket.t()) :: Socket.t()
|
||||
def cancel_pending_loads(socket) do
|
||||
# Cancel any pending batch load messages
|
||||
Enum.each(socket.assigns.pending_batch_tasks, &Process.cancel_timer/1)
|
||||
Enum.each(Map.get(socket.assigns, :pending_batch_tasks, []), &Process.cancel_timer/1)
|
||||
assign(socket, :pending_batch_tasks, [])
|
||||
end
|
||||
|
||||
|
|
@ -333,7 +333,7 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
|
|||
generation = Map.get(socket.assigns, :loading_generation, 0)
|
||||
timer_ref = Process.send_after(self(), {:load_historical_batch, next_batch, generation}, 50)
|
||||
|
||||
assign(socket, :pending_batch_tasks, [timer_ref | socket.assigns.pending_batch_tasks])
|
||||
assign(socket, :pending_batch_tasks, [timer_ref | Map.get(socket.assigns, :pending_batch_tasks, [])])
|
||||
end
|
||||
|
||||
# Handle low zoom (heat map)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue