Skip to content

Commit

Permalink
ft: do not traverse whole state for actions handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Jul 2, 2024
1 parent 24f2bec commit 292e67f
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,6 @@ defmodule Supavisor.ClientHandler do

def try_get_sni(_), do: nil

@spec timeout_check(atom, non_neg_integer) :: {:timeout, non_neg_integer, atom}
defp timeout_check(key, timeout) do
{:timeout, timeout, key}
end

defp db_pid_meta({_, {_, pid}} = _key) do
rkey = Supavisor.Registry.PoolPids
fnode = node(pid)
Expand Down Expand Up @@ -976,18 +971,15 @@ defmodule Supavisor.ClientHandler do
defp handle_prepared_statements(_, _, _), do: nil

@spec handle_actions(map) :: [{:timeout, non_neg_integer, atom}]
defp handle_actions(data) do
Enum.flat_map(data, fn
{:heartbeat_interval, v} = t when v > 0 ->
Logger.debug("ClientHandler: Call timeout #{inspect(t)}")
[timeout_check(:heartbeat_check, v)]

{:idle_timeout, v} = t when v > 0 ->
Logger.debug("ClientHandler: Call timeout #{inspect(t)}")
[timeout_check(:idle_terminate, v)]

_ ->
[]
end)
defp handle_actions(%{} = data) do
heartbeat =
if data.heartbeat_interval > 0,
do: [{:timeout, data.heartbeat_interval, :heartbeat_check}],
else: []

idle =
if data.idle_timeout > 0, do: [{:timeout, data.idle_timeout, :idle_timeout}], else: []

idle ++ heartbeat
end
end

0 comments on commit 292e67f

Please sign in to comment.