Skip to content

Commit

Permalink
chore: use or/2 over ||/2
Browse files Browse the repository at this point in the history
Reason for that is that `a || b` will expand to:

```
case a do
  val when val in [false, nil] -> b
  val -> val
end
```

Which is harder to optimise by the compiler. `or/2` works only with
booleans, so in places where we do not care about returned value or
`nil` cases, it is better to use `or/2`.
  • Loading branch information
hauleth committed Jun 29, 2024
1 parent 1bb4413 commit a24ca5f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ defmodule Supavisor.ClientHandler do
Cachex.get(Supavisor.Cache, key) == {:ok, nil} do
case auth_secrets(info, data.user, key, 15_000) do
{:ok, {method2, secrets2}} = value ->
if method != method2 || Map.delete(secrets.(), :client_key) != secrets2.() do
if method != method2 or Map.delete(secrets.(), :client_key) != secrets2.() do
Logger.warning("ClientHandler: Update secrets and terminate pool")

Cachex.update(
Expand Down Expand Up @@ -632,7 +632,7 @@ defmodule Supavisor.ClientHandler do
db_info =
case Db.get_state_and_mode(pid) do
{:ok, {state, mode} = resp} ->
if state == :busy || mode == :session, do: Db.stop(pid)
if state == :busy or mode == :session, do: Db.stop(pid)
resp

error ->
Expand Down
2 changes: 1 addition & 1 deletion lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ defmodule Supavisor.DbHandler do
)
end

if state == :busy || data.mode == :session do
if state == :busy or data.mode == :session do
:ok = sock_send(data.sock, <<?X, 4::32>>)
:gen_tcp.close(elem(data.sock, 1))
{:stop, {:client_handler_down, data.mode}}
Expand Down

0 comments on commit a24ca5f

Please sign in to comment.