Skip to content

Commit

Permalink
Ignore subscription publish with empty subscribed_fields
Browse files Browse the repository at this point in the history
As written, `Absinthe.Subscribe.publish()` will still broadcast via
pubsub every single mutation results, even if the subscribed fields is
empty. This is because get_subscription_info() will return an empty
array if it does now find any subscribed fields. This is passed down all
the way to the pubsub.

Absinthe.Subscription.Local ultimately ignores this when attempting to
iterate over an empty list.

This can result in significant network traffic among nodes that
ultimately does nothing. When deployed on the cloud in a multi-az
deployment, this can result in significant increase in network traffic
charges.

This patch adds a clause where empty subscribed_fields is ignored.
  • Loading branch information
hosh committed Sep 9, 2022
1 parent df1808c commit c3dd302
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/absinthe/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ defmodule Absinthe.Subscription do
term,
Absinthe.Resolution.t() | [subscription_field_spec]
) :: :ok
def publish(_pubsub, _mutation_result, []), do: :ok

def publish(pubsub, mutation_result, %Absinthe.Resolution{} = info) do
subscribed_fields = get_subscription_fields(info)
publish(pubsub, mutation_result, subscribed_fields)
Expand Down

0 comments on commit c3dd302

Please sign in to comment.