Refactor: reduce nesting depth in 2 functions
Extract nested logic into helper functions to improve readability: - broadcast_task_supervisor.ex: extract broadcast_to_topics/3 helper - log_sanitizer.ex: extract redact_match/1 helper Progress: 2/42 refactoring opportunities fixed
This commit is contained in:
parent
d8606bb609
commit
185266a1f9
2 changed files with 17 additions and 9 deletions
|
|
@ -51,9 +51,7 @@ defmodule Aprsme.BroadcastTaskSupervisor do
|
||||||
# Process in chunks to balance load
|
# Process in chunks to balance load
|
||||||
|> Stream.chunk_every(10)
|
|> Stream.chunk_every(10)
|
||||||
|> Enum.each(fn topic_chunk ->
|
|> Enum.each(fn topic_chunk ->
|
||||||
Enum.each(topic_chunk, fn topic ->
|
broadcast_to_topics(topic_chunk, message, pubsub)
|
||||||
Phoenix.PubSub.broadcast(pubsub, topic, message)
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -102,4 +100,11 @@ defmodule Aprsme.BroadcastTaskSupervisor do
|
||||||
rescue
|
rescue
|
||||||
_ -> 0.0
|
_ -> 0.0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Private helper to broadcast to multiple topics
|
||||||
|
defp broadcast_to_topics(topics, message, pubsub) do
|
||||||
|
Enum.each(topics, fn topic ->
|
||||||
|
Phoenix.PubSub.broadcast(pubsub, topic, message)
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,20 @@ defmodule Aprsme.LogSanitizer do
|
||||||
|
|
||||||
def sanitize_map(data), do: data
|
def sanitize_map(data), do: data
|
||||||
|
|
||||||
|
# Helper to redact a matched sensitive pattern
|
||||||
|
defp redact_match(match) do
|
||||||
|
case String.split(match, ["=", ":"]) do
|
||||||
|
[key, _value] -> "#{key}=[REDACTED]"
|
||||||
|
_ -> "[REDACTED]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Sanitize a string by replacing sensitive patterns
|
Sanitize a string by replacing sensitive patterns
|
||||||
"""
|
"""
|
||||||
def sanitize_string(data) when is_binary(data) do
|
def sanitize_string(data) when is_binary(data) do
|
||||||
Enum.reduce(@sensitive_patterns, data, fn pattern, acc ->
|
Enum.reduce(@sensitive_patterns, data, fn pattern, acc ->
|
||||||
Regex.replace(pattern, acc, fn match ->
|
Regex.replace(pattern, acc, &redact_match/1)
|
||||||
case String.split(match, ["=", ":"]) do
|
|
||||||
[key, _value] -> "#{key}=[REDACTED]"
|
|
||||||
_ -> "[REDACTED]"
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue