Skip to content

Commit

Permalink
Tiny optimization to KV.list_buckets/1 (#185)
Browse files Browse the repository at this point in the history
Removes the unnecessary flat map. The performance difference should be pretty small (tbh I didn't measure), but slightly faster and less memory.
  • Loading branch information
davydog187 authored Jan 9, 2025
1 parent a21ab91 commit bbc2717
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/gnat/jetstream/api/kv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,9 @@ defmodule Gnat.Jetstream.API.KV do
def list_buckets(conn) do
with {:ok, %{streams: streams}} <- Stream.list(conn) do
stream_names =
streams
|> Enum.flat_map(fn bucket ->
if kv_bucket_stream?(bucket) do
[bucket |> String.trim_leading(@stream_prefix)]
else
[]
end
end)
for bucket <- streams, kv_bucket_stream?(bucket) do
String.trim_leading(bucket, @stream_prefix)
end

{:ok, stream_names}
else
Expand Down

0 comments on commit bbc2717

Please sign in to comment.